Skip to content

Commit df3b6f9

Browse files
authored
Apply eslint (#41)
* Lint the project
1 parent 341ea4f commit df3b6f9

36 files changed

+953
-333
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
webpack.config.js

.eslintrc.json

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,40 @@
22
"root": true,
33
"parser": "@typescript-eslint/parser",
44
"parserOptions": {
5-
"ecmaVersion": 6,
6-
"sourceType": "module"
5+
"ecmaVersion": "latest",
6+
"sourceType": "module",
7+
"project": ["./client/tsconfig.json", "./server/tsconfig.json", "./server/tsconfig.eslint.json"]
78
},
89
"plugins": ["@typescript-eslint"],
10+
"extends": ["standard-with-typescript", "plugin:prettier/recommended"],
911
"rules": {
12+
"@typescript-eslint/quotes": ["error", "double"],
13+
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
1014
"@typescript-eslint/naming-convention": "warn",
11-
"@typescript-eslint/semi": "warn",
15+
"@typescript-eslint/no-non-null-assertion": "warn",
16+
"@typescript-eslint/no-floating-promises": "warn",
17+
"@typescript-eslint/semi": "off",
18+
"@typescript-eslint/explicit-function-return-type": "off",
19+
"@typescript-eslint/space-before-function-paren": "off",
20+
"@typescript-eslint/array-type": "off",
21+
"@typescript-eslint/strict-boolean-expressions": "off",
22+
"@typescript-eslint/prefer-nullish-coalescing": "off",
23+
"@typescript-eslint/consistent-type-assertions": "off",
24+
"@typescript-eslint/no-extraneous-class": "off",
1225
"curly": "warn",
1326
"eqeqeq": "warn",
27+
"no-unsafe-finally": "warn",
1428
"no-throw-literal": "warn",
15-
"semi": "off"
29+
"space-before-function-paren": "off",
30+
"semi": "off",
31+
"quotes": "off",
32+
"no-extra-boolean-cast": "off",
33+
"prettier/prettier": [
34+
"error",
35+
{
36+
"endOfLine": "auto"
37+
}
38+
]
1639
},
17-
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
40+
"ignorePatterns": ["out", "**/*.d.ts"]
1841
}

.prettierrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 130,
3+
"trailingComma": "all",
4+
"singleQuote": false
5+
}

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
"editor.formatOnSave": true,
33
"[typescript]": {
44
"editor.defaultFormatter": "esbenp.prettier-vscode"
5-
},
6-
"prettier.printWidth": 130
5+
}
76
}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ All notable changes to the "nwscript-ee-language-server" extension will be docum
3939
## [1.5.0]
4040

4141
- The extension size has been lowered from 14.7 to 4.8 MB.
42+
43+
## [1.5.1]
44+
45+
- Eslint has been configured along with prettier and the project will be linted from now on.

client/src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export function activate(context: ExtensionContext) {
2525
client.start();
2626
}
2727

28-
export function deactivate() {
29-
return client?.stop();
28+
export async function deactivate() {
29+
return await client?.stop();
3030
}

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "https://github.com/PhilippeChab/nwscript-ee-language-server"
99
},
1010
"license": "MIT",
11-
"version": "1.5.0",
11+
"version": "1.5.1",
1212
"author": {
1313
"name": "Philippe Chabot"
1414
},
@@ -148,14 +148,20 @@
148148
},
149149
"devDependencies": {
150150
"@types/node": "14.x",
151-
"@typescript-eslint/eslint-plugin": "^5.21.0",
151+
"@typescript-eslint/eslint-plugin": "^5.33.0",
152152
"@typescript-eslint/parser": "^5.21.0",
153-
"eslint": "^8.14.0",
153+
"eslint": "^8.0.1",
154+
"eslint-config-prettier": "^8.5.0",
155+
"eslint-config-standard-with-typescript": "^22.0.0",
156+
"eslint-plugin-import": "^2.25.2",
157+
"eslint-plugin-n": "^15.0.0",
158+
"eslint-plugin-prettier": "^4.2.1",
159+
"eslint-plugin-promise": "^6.0.0",
154160
"merge-options": "^3.0.4",
155-
"prettier": "^2.6.2",
161+
"prettier": "^2.7.1",
156162
"rimraf": "^3.0.2",
157163
"ts-loader": "^9.3.1",
158-
"typescript": "^4.6.4",
164+
"typescript": "*",
159165
"webpack": "^5.74.0",
160166
"webpack-cli": "^4.10.0"
161167
}

server/scripts/GenerateLibDefinitions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { writeFileSync, readFileSync } from "fs";
22
import { normalize, join } from "path";
3+
34
import { Tokenizer } from "../src/Tokenizer";
45
import { TokenizedScope } from "../src/Tokenizer/Tokenizer";
56

server/src/Documents/Document.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { WorkspaceFilesSystem } from "../WorkspaceFilesSystem";
21
import type { ComplexToken, StructComplexToken } from "../Tokenizer/types";
32
import type DocumentsCollection from "./DocumentsCollection";
43

@@ -11,11 +10,11 @@ export default class Document {
1110
readonly children: string[],
1211
readonly complexTokens: ComplexToken[],
1312
readonly structComplexTokens: StructComplexToken[],
14-
private readonly collection: DocumentsCollection
13+
private readonly collection: DocumentsCollection,
1514
) {}
1615

1716
public getKey() {
18-
return WorkspaceFilesSystem.getFileBasename(this.path);
17+
return this.collection.getKey(this.path);
1918
}
2019

2120
public getChildren(computedChildren: string[] = []): string[] {
@@ -35,7 +34,7 @@ export default class Document {
3534
}
3635

3736
return childDocument.getChildren(computedChildren);
38-
})
37+
}),
3938
);
4039
}
4140

@@ -56,7 +55,7 @@ export default class Document {
5655
}
5756

5857
return childDocument.getGlobalComplexTokensWithRef(computedChildren);
59-
})
58+
}),
6059
);
6160
}
6261

@@ -77,7 +76,7 @@ export default class Document {
7776
}
7877

7978
return childDocument.getGlobalComplexTokens(computedChildren);
80-
})
79+
}),
8180
);
8281
}
8382

@@ -98,7 +97,7 @@ export default class Document {
9897
}
9998

10099
return childDocument.getGlobalStructComplexTokensWithRef(computedChildren);
101-
})
100+
}),
102101
);
103102
}
104103

@@ -119,7 +118,7 @@ export default class Document {
119118
}
120119

121120
return childDocument.getGlobalStructComplexTokens(computedChildren);
122-
})
121+
}),
123122
);
124123
}
125124
}

server/src/Documents/DocumentsCollection.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { join } from "path";
1+
import { basename, join } from "path";
2+
import { fileURLToPath } from "url";
3+
import { readFileSync } from "fs";
4+
import { TextDocument } from "vscode-languageserver-textdocument";
25

36
import type { Tokenizer } from "../Tokenizer";
47
import type { ComplexToken } from "../Tokenizer/types";
58
import { GlobalScopeTokenizationResult, TokenizedScope } from "../Tokenizer/Tokenizer";
69
import { Dictionnary } from "../Utils";
7-
import { WorkspaceFilesSystem } from "../WorkspaceFilesSystem";
810
import Document from "./Document";
9-
import { TextDocument } from "vscode-languageserver-textdocument";
11+
import { FILES_EXTENSION } from "../WorkspaceFilesSystem/WorkspaceFilesSystem";
1012

1113
export default class DocumentsCollection extends Dictionnary<string, Document> {
1214
public readonly standardLibComplexTokens: ComplexToken[] = [];
@@ -15,7 +17,7 @@ export default class DocumentsCollection extends Dictionnary<string, Document> {
1517
super();
1618

1719
this.standardLibComplexTokens = JSON.parse(
18-
WorkspaceFilesSystem.readFileSync(join(__dirname, "..", "resources", "standardLibDefinitions.json")).toString()
20+
readFileSync(join(__dirname, "..", "resources", "standardLibDefinitions.json")).toString(),
1921
).complexTokens as ComplexToken[];
2022
}
2123

@@ -31,12 +33,20 @@ export default class DocumentsCollection extends Dictionnary<string, Document> {
3133
return new Document(filePath, globalScope.children, globalScope.complexTokens, globalScope.structComplexTokens, this);
3234
}
3335

36+
public getKey(path: string) {
37+
return basename(path, FILES_EXTENSION).slice(0, -1);
38+
}
39+
40+
public getFromPath(path: string) {
41+
return this.get(this.getKey(path));
42+
}
43+
3444
public createDocument(filePath: string, globalScope: GlobalScopeTokenizationResult) {
3545
this.addDocument(this.initializeDocument(filePath, globalScope));
3646
}
3747

3848
public updateDocument(document: TextDocument, tokenizer: Tokenizer) {
39-
const filePath = WorkspaceFilesSystem.fileUriToPath(document.uri);
49+
const filePath = fileURLToPath(document.uri);
4050
const globalScope = tokenizer.tokenizeContent(document.getText(), TokenizedScope.global);
4151

4252
this.overwriteDocument(this.initializeDocument(filePath, globalScope));

0 commit comments

Comments
 (0)