Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8a801bc

Browse files
committed
added prettier, fixed formatting and linting errors
1 parent 9d03c5a commit 8a801bc

23 files changed

+3455
-3106
lines changed

‎.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@typescript-eslint/no-explicit-any": "warn",
1414
"@typescript-eslint/explicit-module-boundary-types": "warn",
1515
"@typescript-eslint/explicit-function-return-type": "warn",
16-
"@typescript-eslint/no-unused-vars": "off",
16+
"@typescript-eslint/no-unused-vars": "warn",
1717
"@typescript-eslint/no-control-regex": "off",
1818
"@typescript-eslint/no-constant-condition": "off"
1919
}

‎.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"printWidth": 100,
3+
"trailingComma": "none",
4+
"arrowParens": "avoid",
5+
"parser": "typescript",
6+
"singleQuote": true,
7+
"tabWidth": 2
8+
}

‎package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jspython-interpreter",
3-
"version": "2.1.10",
3+
"version": "2.1.11",
44
"description": "JSPython is a javascript implementation of Python language that runs within web browser or NodeJS environment",
55
"keywords": [
66
"python",
@@ -43,6 +43,7 @@
4343
"@typescript-eslint/parser": "^4.8.2",
4444
"ace-builds": "^1.4.12",
4545
"eslint": "^7.14.0",
46+
"husky": "^4.2.5",
4647
"jest": "^26.6.3",
4748
"rollup": "^2.52.7",
4849
"rollup-plugin-copy": "^3.4.0",
@@ -53,5 +54,10 @@
5354
"ts-jest": "^26.4.4",
5455
"tslib": "^2.3.0",
5556
"typescript": "^4.3.5"
56-
}
57+
},
58+
"husky": {
59+
"hooks": {
60+
"pre-commit": "npm run lint && npm run test"
61+
}
62+
}
5763
}

‎src/common/ast-types.ts

Lines changed: 55 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
import {
2-
ExpressionOperators,
3-
LogicalOperators,
4-
OperationTypes,
5-
Operators,
6-
} from "./operators";
7-
import { getTokenLoc, getTokenValue, Token } from "./token-types";
1+
import { ExpressionOperators, LogicalOperators } from './operators';
2+
import { getTokenLoc, getTokenValue, Token } from './token-types';
83

94
export type AstNodeType =
10-
| "assign"
11-
| "binOp"
12-
| "const"
13-
| "logicalOp"
14-
| "getSingleVar"
15-
| "setSingleVar"
16-
| "dotObjectAccess"
17-
| "bracketObjectAccess"
18-
| "funcCall"
19-
| "funcDef"
20-
| "arrowFuncDef"
21-
| "createObject"
22-
| "createArray"
23-
| "if"
24-
| "for"
25-
| "while"
26-
| "tryExcept"
27-
| "raise"
28-
| "import"
29-
| "comment"
30-
| "return"
31-
| "continue"
32-
| "break";
5+
| 'assign'
6+
| 'binOp'
7+
| 'const'
8+
| 'logicalOp'
9+
| 'getSingleVar'
10+
| 'setSingleVar'
11+
| 'dotObjectAccess'
12+
| 'bracketObjectAccess'
13+
| 'funcCall'
14+
| 'funcDef'
15+
| 'arrowFuncDef'
16+
| 'createObject'
17+
| 'createArray'
18+
| 'if'
19+
| 'for'
20+
| 'while'
21+
| 'tryExcept'
22+
| 'raise'
23+
| 'import'
24+
| 'comment'
25+
| 'return'
26+
| 'continue'
27+
| 'break';
3328

3429
export interface NameAlias {
3530
name: string;
@@ -61,12 +56,8 @@ export abstract class AstNode {
6156
}
6257

6358
export class AssignNode extends AstNode {
64-
constructor(
65-
public target: AstNode,
66-
public source: AstNode,
67-
public loc: Uint16Array
68-
) {
69-
super("assign");
59+
constructor(public target: AstNode, public source: AstNode, public loc: Uint16Array) {
60+
super('assign');
7061
this.loc = loc;
7162
}
7263
}
@@ -75,56 +66,49 @@ export class ConstNode extends AstNode {
7566
public value: number | string | boolean | null;
7667

7768
constructor(token: Token) {
78-
super("const");
69+
super('const');
7970
this.value = getTokenValue(token);
8071
this.loc = getTokenLoc(token);
8172
}
8273
}
8374

8475
export class CommentNode extends AstNode {
8576
constructor(public comment: string, public loc: Uint16Array) {
86-
super("comment");
77+
super('comment');
8778
this.loc = loc;
8879
}
8980
}
9081

9182
export class ReturnNode extends AstNode {
92-
constructor(
93-
public returnValue: AstNode | undefined = undefined,
94-
public loc: Uint16Array
95-
) {
96-
super("return");
83+
constructor(public returnValue: AstNode | undefined = undefined, public loc: Uint16Array) {
84+
super('return');
9785
this.loc = loc;
9886
}
9987
}
10088

10189
export class RaiseNode extends AstNode {
102-
constructor(
103-
public errorName: string,
104-
public errorMessageAst: AstNode,
105-
public loc: Uint16Array
106-
) {
107-
super("raise");
90+
constructor(public errorName: string, public errorMessageAst: AstNode, public loc: Uint16Array) {
91+
super('raise');
10892
this.loc = loc;
10993
}
11094
}
11195

11296
export class ContinueNode extends AstNode {
11397
constructor() {
114-
super("continue");
98+
super('continue');
11599
}
116100
}
117101

118102
export class BreakNode extends AstNode {
119103
constructor() {
120-
super("break");
104+
super('break');
121105
}
122106
}
123107

124108
export class SetSingleVarNode extends AstNode {
125109
public name: string;
126110
constructor(token: Token) {
127-
super("setSingleVar");
111+
super('setSingleVar');
128112
this.name = token[0] as string;
129113
this.loc = getTokenLoc(token);
130114
}
@@ -133,12 +117,8 @@ export class SetSingleVarNode extends AstNode {
133117
export class FunctionCallNode extends AstNode implements IsNullCoelsing {
134118
public nullCoelsing: boolean | undefined = undefined;
135119

136-
constructor(
137-
public name: string,
138-
public paramNodes: AstNode[] | null,
139-
public loc: Uint16Array
140-
) {
141-
super("funcCall");
120+
constructor(public name: string, public paramNodes: AstNode[] | null, public loc: Uint16Array) {
121+
super('funcCall');
142122
this.loc = loc;
143123
}
144124
}
@@ -150,18 +130,14 @@ export class FunctionDefNode extends AstNode implements FuncDefNode {
150130
public isAsync: boolean,
151131
public loc: Uint16Array
152132
) {
153-
super("funcDef");
133+
super('funcDef');
154134
this.loc = loc;
155135
}
156136
}
157137

158138
export class ArrowFuncDefNode extends AstNode implements FuncDefNode {
159-
constructor(
160-
public funcAst: AstBlock,
161-
public params: string[],
162-
public loc: Uint16Array
163-
) {
164-
super("arrowFuncDef");
139+
constructor(public funcAst: AstBlock, public params: string[], public loc: Uint16Array) {
140+
super('arrowFuncDef');
165141
this.loc = loc;
166142
}
167143
}
@@ -173,7 +149,7 @@ export class IfNode extends AstNode {
173149
public elseBody: AstNode[] | undefined = undefined,
174150
public loc: Uint16Array
175151
) {
176-
super("if");
152+
super('if');
177153
this.loc = loc;
178154
}
179155
}
@@ -187,7 +163,7 @@ export class TryExceptNode extends AstNode {
187163

188164
public loc: Uint16Array
189165
) {
190-
super("tryExcept");
166+
super('tryExcept');
191167
this.loc = loc;
192168
}
193169
}
@@ -199,18 +175,14 @@ export class ForNode extends AstNode {
199175
public body: AstNode[],
200176
public loc: Uint16Array
201177
) {
202-
super("for");
178+
super('for');
203179
this.loc = loc;
204180
}
205181
}
206182

207183
export class WhileNode extends AstNode {
208-
constructor(
209-
public condition: AstNode,
210-
public body: AstNode[],
211-
public loc: Uint16Array
212-
) {
213-
super("while");
184+
constructor(public condition: AstNode, public body: AstNode[], public loc: Uint16Array) {
185+
super('while');
214186
this.loc = loc;
215187
}
216188
}
@@ -222,7 +194,7 @@ export class ImportNode extends AstNode {
222194
public parts: NameAlias[] | undefined = undefined,
223195
public loc: Uint16Array
224196
) {
225-
super("import");
197+
super('import');
226198
this.loc = loc;
227199
}
228200
}
@@ -232,7 +204,7 @@ export class GetSingleVarNode extends AstNode implements IsNullCoelsing {
232204
nullCoelsing: boolean | undefined = undefined;
233205

234206
constructor(token: Token, nullCoelsing: boolean | undefined = undefined) {
235-
super("getSingleVar");
207+
super('getSingleVar');
236208
this.name = token[0] as string;
237209
this.nullCoelsing = nullCoelsing;
238210
this.loc = getTokenLoc(token);
@@ -241,21 +213,21 @@ export class GetSingleVarNode extends AstNode implements IsNullCoelsing {
241213

242214
export class DotObjectAccessNode extends AstNode {
243215
constructor(public nestedProps: AstNode[], public loc: Uint16Array) {
244-
super("dotObjectAccess");
216+
super('dotObjectAccess');
245217
this.loc = loc;
246218
}
247219
}
248220

249221
export class CreateObjectNode extends AstNode {
250222
constructor(public props: ObjectPropertyInfo[], public loc: Uint16Array) {
251-
super("createObject");
223+
super('createObject');
252224
this.loc = loc;
253225
}
254226
}
255227

256228
export class CreateArrayNode extends AstNode {
257229
constructor(public items: AstNode[], public loc: Uint16Array) {
258-
super("createArray");
230+
super('createArray');
259231
this.loc = loc;
260232
}
261233
}
@@ -267,7 +239,7 @@ export class BracketObjectAccessNode extends AstNode {
267239
public nullCoalescing: boolean | undefined = undefined,
268240
public loc: Uint16Array
269241
) {
270-
super("bracketObjectAccess");
242+
super('bracketObjectAccess');
271243
this.loc = loc;
272244
}
273245
}
@@ -279,7 +251,7 @@ export interface LogicalNodeItem {
279251

280252
export class LogicalOpNode extends AstNode {
281253
constructor(public items: LogicalNodeItem[], public loc: Uint16Array) {
282-
super("logicalOp");
254+
super('logicalOp');
283255
this.loc = loc;
284256
}
285257
}
@@ -291,14 +263,14 @@ export class BinOpNode extends AstNode {
291263
public right: AstNode,
292264
public loc: Uint16Array
293265
) {
294-
super("binOp");
266+
super('binOp');
295267
this.loc = loc;
296268
}
297269
}
298270

299271
export interface AstBlock {
300272
name: string;
301-
type: "module" | "func" | "if" | "for" | "while" | "trycatch";
273+
type: 'module' | 'func' | 'if' | 'for' | 'while' | 'trycatch';
302274
funcs: FunctionDefNode[];
303275
body: AstNode[];
304276
}

‎src/common/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './ast-types';
22
export * from './token-types';
33
export * from './parser-types';
4-
export * from './operators';
4+
export * from './operators';

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /