Skip to content

Migrate to eslint #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {}
}
45 changes: 45 additions & 0 deletions .yarnclean
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# test directories
__tests__
test
tests
powered-test

# asset directories
docs
doc
website
images
assets

# examples
example
examples

# code coverage directories
coverage
.nyc_output

# build scripts
Makefile
Gulpfile.js
Gruntfile.js

# configs
appveyor.yml
circle.yml
codeship-services.yml
codeship-steps.yml
wercker.yml
.tern-project
.gitattributes
.editorconfig
.*ignore
.eslintrc
.jshintrc
.flowconfig
.documentup.json
.yarn-metadata.json
.travis.yml

# misc
*.md
20 changes: 7 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
"multi-root ready"
],
"homepage": "https://github.com/haskell/vscode-haskell",
"repository": {
"type": "git",
"url": "https://github.com/haskell/vscode-haskell.git"
},
"repository": "https://github.com/haskell/vscode-haskell.git",
"bugs": {
"url": "https://github.com/haskell/vscode-haskell/issues"
},
Expand Down Expand Up @@ -537,10 +534,10 @@
"vscode:prepublish": "webpack --mode production",
"webpack": "webpack --mode none",
"watch": "webpack --mode development --watch",
"tslint": "tslint -p tsconfig.json -c tslint.json --format stylish 'src/**/*.ts'",
"tslint-fix": "tslint --fix -p tsconfig.json -c tslint.json --format stylish 'src/**/*.ts'",
"lint": "eslint -c .eslintrc.json --ext .ts src",
"lint-fix": "eslint --fix -c .eslintrc.json --ext .ts src",
"push-tag": "git tag -a $npm_package_version -m \"Version $npm_package_version\" && git push origin $npm_package_version",
"pretest": "tsc -p ./",
"pretest": "tsc --alwaysStrict -p ./",
"format": "prettier . --write",
"test": "node ./out/test/runTest.js"
},
Expand All @@ -560,19 +557,17 @@
"@types/vscode": "^1.74.0",
"@types/which": "^2.0.1",
"@types/yauzl": "^2.9.1",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.0",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"@vscode/test-electron": "^2.2.1",
"eslint": "^8.30.0",
"eslint-webpack-plugin": "^3.2.0",
"glob": "^8.0.3",
"husky": "^8.0.2",
"mocha": "^10.2.0",
"prettier": "^2.8.1",
"pretty-quick": "^3.1.2",
"set-value": ">=4.0.1",
"ts-loader": "^9.4.2",
"tslint": "^6.1.3",
"tslint-loader": "^3.5.4",
"typescript": "^4.9.4",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
Expand All @@ -583,7 +578,6 @@
"dependencies": {
"bent": "^7.3.12",
"cheerio": "^1.0.0-rc.12",
"extend": ">=3.0.2",
"js-yaml": "^4.1.0",
"lodash-es": "^4.17.21",
"lru-cache": "^7.14.1",
Expand Down
10 changes: 4 additions & 6 deletions src/commands/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export namespace CommandNames {
export const ImportIdentifierCommandName = 'haskell.commands.importIdentifier';
export const RestartServerCommandName = 'haskell.commands.restartServer';
export const StartServerCommandName = 'haskell.commands.startServer';
export const StopServerCommandName = 'haskell.commands.stopServer';
}
export const ImportIdentifierCommandName = 'haskell.commands.importIdentifier';
export const RestartServerCommandName = 'haskell.commands.restartServer';
export const StartServerCommandName = 'haskell.commands.startServer';
export const StopServerCommandName = 'haskell.commands.stopServer';
68 changes: 32 additions & 36 deletions src/commands/importIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as yaml from 'js-yaml';
import escapeRegExp from 'lodash-es/escapeRegExp';
import * as LRUCache from 'lru-cache';
import * as vscode from 'vscode';
import { CommandNames } from './constants';
import { ImportIdentifierCommandName } from './constants';

const getJson = bent('json');

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

export namespace ImportIdentifier {
'use strict';

export function registerCommand(): vscode.Disposable {
return vscode.commands.registerTextEditorCommand(CommandNames.ImportIdentifierCommandName, async (editor, edit) => {
// \u0027 is ' (satisfies the linter)
const identifierRegExp = new RegExp('[' + escapeRegExp('!#$%&*+./<=>?@^|-~:') + ']+' + '|' + '[\\w\u0027]+');

const identifierRange = editor.selection.isEmpty
? editor.document.getWordRangeAtPosition(editor.selections[0].active, identifierRegExp)
: new vscode.Range(editor.selection.start, editor.selection.end);

if (!identifierRange) {
vscode.window.showErrorMessage(
'No Haskell identifier found at the cursor (here is the regex used: ' + identifierRegExp + ' )'
);
return;
}

const response: any[] = await askHoogleCached(editor.document.getText(identifierRange));

const choice = await vscode.window.showQuickPick(
response
.filter((result) => result.module.name)
.map((result) => ({
result,
label: result.package.name,
description: result.module.name + ' -- ' + (cheerio.load as any)(result.item, { xml: {} }).text(),
}))
export function registerCommand(): vscode.Disposable {
return vscode.commands.registerTextEditorCommand(ImportIdentifierCommandName, async (editor, edit) => {
// \u0027 is ' (satisfies the linter)
const identifierRegExp = new RegExp('[' + escapeRegExp('!#$%&*+./<=>?@^|-~:') + ']+' + '|' + '[\\w\u0027]+');

const identifierRange = editor.selection.isEmpty
? editor.document.getWordRangeAtPosition(editor.selections[0].active, identifierRegExp)
: new vscode.Range(editor.selection.start, editor.selection.end);

if (!identifierRange) {
vscode.window.showErrorMessage(
'No Haskell identifier found at the cursor (here is the regex used: ' + identifierRegExp + ' )'
);
return;
}

if (!choice) {
return;
}
const response: any[] = await askHoogleCached(editor.document.getText(identifierRange));

await doImport({ mod: choice.result.module.name, package: choice.result.package.name });
});
}
const choice = await vscode.window.showQuickPick(
response
.filter((result) => result.module.name)
.map((result) => ({
result,
label: result.package.name,
description: result.module.name + ' -- ' + (cheerio.load as any)(result.item, { xml: {} }).text(),
}))
);

if (!choice) {
return;
}

await doImport({ mod: choice.result.module.name, package: choice.result.package.name });
});
}
Loading