Skip to content

Commit d38889a

Browse files
committed
Migrate to eslint and fix some lints
1 parent 9b57c90 commit d38889a

14 files changed

+390
-598
lines changed

.eslintrc.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/recommended"
9+
],
10+
"overrides": [
11+
],
12+
"parser": "@typescript-eslint/parser",
13+
"parserOptions": {
14+
"ecmaVersion": "latest",
15+
"sourceType": "module"
16+
},
17+
"plugins": [
18+
"@typescript-eslint"
19+
],
20+
"rules": {
21+
}
22+
}

.yarnclean

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# test directories
2+
__tests__
3+
test
4+
tests
5+
powered-test
6+
7+
# asset directories
8+
docs
9+
doc
10+
website
11+
images
12+
assets
13+
14+
# examples
15+
example
16+
examples
17+
18+
# code coverage directories
19+
coverage
20+
.nyc_output
21+
22+
# build scripts
23+
Makefile
24+
Gulpfile.js
25+
Gruntfile.js
26+
27+
# configs
28+
appveyor.yml
29+
circle.yml
30+
codeship-services.yml
31+
codeship-steps.yml
32+
wercker.yml
33+
.tern-project
34+
.gitattributes
35+
.editorconfig
36+
.*ignore
37+
.eslintrc
38+
.jshintrc
39+
.flowconfig
40+
.documentup.json
41+
.yarn-metadata.json
42+
.travis.yml
43+
44+
# misc
45+
*.md

package.json

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
"multi-root ready"
1818
],
1919
"homepage": "https://github.com/haskell/vscode-haskell",
20-
"repository": {
21-
"type": "git",
22-
"url": "https://github.com/haskell/vscode-haskell.git"
23-
},
20+
"repository": "https://github.com/haskell/vscode-haskell.git",
2421
"bugs": {
2522
"url": "https://github.com/haskell/vscode-haskell/issues"
2623
},
@@ -537,10 +534,10 @@
537534
"vscode:prepublish": "webpack --mode production",
538535
"webpack": "webpack --mode none",
539536
"watch": "webpack --mode development --watch",
540-
"tslint": "tslint -p tsconfig.json -c tslint.json --format stylish 'src/**/*.ts'",
541-
"tslint-fix": "tslint --fix -p tsconfig.json -c tslint.json --format stylish 'src/**/*.ts'",
537+
"lint": "eslint -c .eslintrc.json --ext .ts src",
538+
"lint-fix": "eslint --fix -c .eslintrc.json --ext .ts src",
542539
"push-tag": "git tag -a $npm_package_version -m \"Version $npm_package_version\" && git push origin $npm_package_version",
543-
"pretest": "tsc -p ./",
540+
"pretest": "tsc --alwaysStrict -p ./",
544541
"format": "prettier . --write",
545542
"test": "node ./out/test/runTest.js"
546543
},
@@ -560,19 +557,16 @@
560557
"@types/vscode": "^1.74.0",
561558
"@types/which": "^2.0.1",
562559
"@types/yauzl": "^2.9.1",
563-
"@typescript-eslint/eslint-plugin": "^5.47.1",
564-
"@typescript-eslint/parser": "^5.47.0",
560+
"@typescript-eslint/eslint-plugin": "^5.48.2",
561+
"@typescript-eslint/parser": "^5.48.2",
565562
"@vscode/test-electron": "^2.2.1",
566563
"eslint": "^8.30.0",
567564
"glob": "^8.0.3",
568565
"husky": "^8.0.2",
569566
"mocha": "^10.2.0",
570567
"prettier": "^2.8.1",
571568
"pretty-quick": "^3.1.2",
572-
"set-value": ">=4.0.1",
573569
"ts-loader": "^9.4.2",
574-
"tslint": "^6.1.3",
575-
"tslint-loader": "^3.5.4",
576570
"typescript": "^4.9.4",
577571
"webpack": "^5.75.0",
578572
"webpack-cli": "^5.0.1"
@@ -583,7 +577,6 @@
583577
"dependencies": {
584578
"bent": "^7.3.12",
585579
"cheerio": "^1.0.0-rc.12",
586-
"extend": ">=3.0.2",
587580
"js-yaml": "^4.1.0",
588581
"lodash-es": "^4.17.21",
589582
"lru-cache": "^7.14.1",

src/commands/constants.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export namespace CommandNames {
2-
export const ImportIdentifierCommandName = 'haskell.commands.importIdentifier';
3-
export const RestartServerCommandName = 'haskell.commands.restartServer';
4-
export const StartServerCommandName = 'haskell.commands.startServer';
5-
export const StopServerCommandName = 'haskell.commands.stopServer';
6-
}
1+
export const ImportIdentifierCommandName = 'haskell.commands.importIdentifier';
2+
export const RestartServerCommandName = 'haskell.commands.restartServer';
3+
export const StartServerCommandName = 'haskell.commands.startServer';
4+
export const StopServerCommandName = 'haskell.commands.stopServer';

src/commands/importIdentifier.ts

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as yaml from 'js-yaml';
44
import escapeRegExp from 'lodash-es/escapeRegExp';
55
import * as LRUCache from 'lru-cache';
66
import * as vscode from 'vscode';
7-
import { CommandNames } from './constants';
7+
import { ImportIdentifierCommandName } from './constants';
88

99
const getJson = bent('json');
1010

@@ -79,42 +79,38 @@ const doImport = async (arg: { mod: string; package: string }): Promise<void> =>
7979
);
8080
};
8181

82-
export namespace ImportIdentifier {
83-
'use strict';
84-
85-
export function registerCommand(): vscode.Disposable {
86-
return vscode.commands.registerTextEditorCommand(CommandNames.ImportIdentifierCommandName, async (editor, edit) => {
87-
// \u0027 is ' (satisfies the linter)
88-
const identifierRegExp = new RegExp('[' + escapeRegExp('!#$%&*+./<=>?@^|-~:') + ']+' + '|' + '[\\w\u0027]+');
89-
90-
const identifierRange = editor.selection.isEmpty
91-
? editor.document.getWordRangeAtPosition(editor.selections[0].active, identifierRegExp)
92-
: new vscode.Range(editor.selection.start, editor.selection.end);
93-
94-
if (!identifierRange) {
95-
vscode.window.showErrorMessage(
96-
'No Haskell identifier found at the cursor (here is the regex used: ' + identifierRegExp + ' )'
97-
);
98-
return;
99-
}
100-
101-
const response: any[] = await askHoogleCached(editor.document.getText(identifierRange));
102-
103-
const choice = await vscode.window.showQuickPick(
104-
response
105-
.filter((result) => result.module.name)
106-
.map((result) => ({
107-
result,
108-
label: result.package.name,
109-
description: result.module.name + ' -- ' + (cheerio.load as any)(result.item, { xml: {} }).text(),
110-
}))
82+
export function registerCommand(): vscode.Disposable {
83+
return vscode.commands.registerTextEditorCommand(ImportIdentifierCommandName, async (editor, edit) => {
84+
// \u0027 is ' (satisfies the linter)
85+
const identifierRegExp = new RegExp('[' + escapeRegExp('!#$%&*+./<=>?@^|-~:') + ']+' + '|' + '[\\w\u0027]+');
86+
87+
const identifierRange = editor.selection.isEmpty
88+
? editor.document.getWordRangeAtPosition(editor.selections[0].active, identifierRegExp)
89+
: new vscode.Range(editor.selection.start, editor.selection.end);
90+
91+
if (!identifierRange) {
92+
vscode.window.showErrorMessage(
93+
'No Haskell identifier found at the cursor (here is the regex used: ' + identifierRegExp + ' )'
11194
);
95+
return;
96+
}
11297

113-
if (!choice) {
114-
return;
115-
}
98+
const response: any[] = await askHoogleCached(editor.document.getText(identifierRange));
11699

117-
await doImport({ mod: choice.result.module.name, package: choice.result.package.name });
118-
});
119-
}
100+
const choice = await vscode.window.showQuickPick(
101+
response
102+
.filter((result) => result.module.name)
103+
.map((result) => ({
104+
result,
105+
label: result.package.name,
106+
description: result.module.name + ' -- ' + (cheerio.load as any)(result.item, { xml: {} }).text(),
107+
}))
108+
);
109+
110+
if (!choice) {
111+
return;
112+
}
113+
114+
await doImport({ mod: choice.result.module.name, package: choice.result.package.name });
115+
});
120116
}

0 commit comments

Comments
 (0)