Skip to content

Commit

Permalink
chore: Update lint rules and fix (#2551)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Feb 27, 2023
1 parent 44237e9 commit 465e3f8
Show file tree
Hide file tree
Showing 178 changed files with 1,112 additions and 571 deletions.
81 changes: 68 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,93 @@
module.exports = {
/**
* @type { import("eslint").Linter.Config }
*/
const config = {
root: true,
reportUnusedDisableDirectives: true,
env: {
node: true,
jest: true,
es2017: true,
es2020: true,
},
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
extends: [
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'eslint:recommended',
'plugin:node/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:promise/recommended',
'plugin:prettier/recommended',
// 'plugin:unicorn/recommended',
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
},
ignorePatterns: ['**/*.d.ts', '**/node_modules/**', 'packages/client/server/**', 'packages/*/dist/**'],
ignorePatterns: [
'**/*.d.ts',
'**/node_modules/**',
'packages/client/server/**',
'packages/*/dist/**',
'packages/*/out/**',
'**/temp/**',
'packages/client/settingsViewer/**',
],
plugins: ['import', 'unicorn', 'simple-import-sort'],
rules: {
'node/no-unsupported-features/es-syntax': 'off',
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
quotes: ['warn', 'single', { avoidEscape: true }],

// e.g. "@typescript-eslint/explicit-function-return-type": "off",
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': ['warn', { ignoreRestSiblings: true, argsIgnorePattern: '^_' }],
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'node/no-missing-import': [
'error',
{
allowModules: ['vscode'],
tryExtensions: ['.js', '.d.ts', '.ts'],
},
],
'node/no-unpublished-import': 'off',
'promise/catch-or-return': ['error', { terminationMethod: ['catch', 'finally'] }],
},
overrides: [
{
files: ['**/*.ts', '**/*.mts', '**/*.cts'],
extends: ['plugin:@typescript-eslint/recommended', 'plugin:import/typescript'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
// '@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
// '@typescript-eslint/no-non-null-assertion': 'off',
// '@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': ['warn', { ignoreRestSiblings: true, argsIgnorePattern: '^_' }],
},
},
{
files: ['*.json'],
rules: {
quotes: ['error', 'double'],
},
},
{
files: ['**/*.js', '**/*.mjs'],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
rules: {
'node/no-unsupported-features/es-syntax': 'off',
},
},
],
settings: {
'import/core-modules': ['vscode'],
},
};

module.exports = config;
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: yarn
- run: yarn build
- run: yarn lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ logs
npm-debug.log*

.cspellcache
.eslintcache

# Runtime data
pids
Expand Down
3 changes: 1 addition & 2 deletions docs/_scripts/extract-commands.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */

// eslint-disable-next-line node/no-unpublished-require
const package = require('../../package.json');

const commands = package.contributes.commands;
Expand Down
3 changes: 1 addition & 2 deletions docs/_scripts/extract-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */

// eslint-disable-next-line node/no-unpublished-require
const package = require('../../package.json');

const configSections = package.contributes.configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line node/no-missing-require, node/no-unpublished-require
require('./.pnp.js').setup();

/** @type { import("@cspell/cspell-types").CSpellUserSettings } */
Expand Down
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2523,7 +2523,8 @@
"test-vsce-build": "vsce package -o ./temp",
"remove-test-files": "shx rm -rf \"packages/*/{out,dist,settingsViewer}/**/*.test.js\"",
"vscode:prepublish": "yarn run build-production && yarn run remove-test-files",
"lint": "yarn workspaces run lint && yarn prettier:check",
"lint": "yarn lint:eslint && yarn prettier:fix",
"lint:eslint": "eslint . --fix --cache",
"lint-docs": "prettier -w \"docs/**/*.{md,markdown,yaml,yml,json,html,htm,js,ts}\"",
"lint-docs-ci": "prettier -c \"docs/**/*.{md,markdown,yaml,yml,json,html,htm,js,ts}\"",
"test-client-integration": "yarn workspace integration-tests test-integration",
Expand All @@ -2532,10 +2533,19 @@
},
"devDependencies": {
"@tsconfig/node16": "^1.0.3",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"@vscode/vsce": "^2.18.0",
"eslint": "^7.32.0",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
"eslint-import-resolver-typescript": "^3.5.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unicorn": "^45.0.2",
"inject-markdown": "^1.5.0",
"ovsx": "^0.8.0",
"prettier": "^2.8.4",
Expand Down
1 change: 0 additions & 1 deletion packages/___buildTools/.eslintrc.js

This file was deleted.

7 changes: 5 additions & 2 deletions packages/___buildTools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"build": "tsc -p .",
"clean-build": "yarn run clean && yarn run build",
"clean": "shx rm -rf out dist coverage",
"lint": "eslint \"src/**/*.ts\" \"*.js\"",
"test": "echo No tests yet.",
"watch": "tsc -p . --watch"
},
Expand All @@ -34,6 +33,10 @@
"ts-jest": "^29.0.5"
},
"dependencies": {
"commander": "^10.0.0"
"commander": "^10.0.0",
"json-schema": "0.4.0"
},
"engines": {
"node": ">16.0.0"
}
}
1 change: 1 addition & 0 deletions packages/___buildTools/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command } from 'commander';

import { commandUpdatePackageCSpellSchema } from './updatePackageCSpellSchema';

const program = new Command();
Expand Down
1 change: 0 additions & 1 deletion packages/__locale-resolver/.eslintrc.js

This file was deleted.

4 changes: 3 additions & 1 deletion packages/__locale-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"build": "tsc -p .",
"clean-build": "yarn run clean && yarn run build",
"clean": "shx rm -rf out dist coverage",
"lint": "eslint \"src/**/*.ts\" \"*.js\"",
"test": "jest",
"watch": "tsc -p . --watch",
"prepare": "yarn build"
Expand All @@ -25,5 +24,8 @@
},
"dependencies": {
"vscode-uri": "^3.0.7"
},
"engines": {
"node": ">16.0.0"
}
}
4 changes: 2 additions & 2 deletions packages/__locale-resolver/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { isValidCode, normalizeCode, lookupLocaleInfo, parseLocale, formatLocale } from './iso639-1';
export type { Locale, ScriptInfo, LocaleInfo } from './iso639-1';
export type { Locale, LocaleInfo, ScriptInfo } from './iso639-1';
export { formatLocale, isValidCode, lookupLocaleInfo, normalizeCode, parseLocale } from './iso639-1';
2 changes: 1 addition & 1 deletion packages/__locale-resolver/src/iso639-1/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { normalizeCode, isValidCode, lookupLocaleInfo, getScriptInfo, parseLocale } from './index';
import { getScriptInfo, isValidCode, lookupLocaleInfo, normalizeCode, parseLocale } from './index';

describe('Validation', () => {
test.each`
Expand Down
1 change: 0 additions & 1 deletion packages/__locale-resolver/src/iso639-1/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { codes } from './languageCodes';
import { scriptCodes } from './scriptCodes';

Expand Down
1 change: 0 additions & 1 deletion packages/__utils/.eslintrc.js

This file was deleted.

4 changes: 3 additions & 1 deletion packages/__utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"build": "tsc -p .",
"clean-build": "yarn run clean && yarn run build",
"clean": "shx rm -rf out dist coverage",
"lint": "eslint \"src/**/*.ts\" \"*.js\"",
"test": "jest",
"watch": "tsc -p . --watch"
},
Expand All @@ -42,5 +41,8 @@
},
"dependencies": {
"vscode-uri": "^3.0.7"
},
"engines": {
"node": ">16.0.0"
}
}
3 changes: 2 additions & 1 deletion packages/__utils/src/file.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fileExists } from './file';
import { URI as Uri } from 'vscode-uri';

import { fileExists } from './file';

describe('Validate file', () => {
test('fileExists', async () => {
await expect(fileExists(Uri.file(__filename))).resolves.toBe(true);
Expand Down
1 change: 1 addition & 0 deletions packages/__utils/src/file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { access } from 'fs/promises';
import { URI as Uri } from 'vscode-uri';

import { isErrnoException } from './errors';

const FileNotFoundErrorCodes: Record<string, undefined | true> = {
Expand Down
4 changes: 2 additions & 2 deletions packages/__utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './util';
export * from './uriHelper';
export * from './errors';
export { LogFileConnection } from './logFile';
export * from './uriHelper';
export * from './util';
2 changes: 1 addition & 1 deletion packages/__utils/src/log.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logError, log, logDebug, logInfo, setWorkspaceFolders, logger } from './log';
import { log, logDebug, logError, logger, logInfo, setWorkspaceFolders } from './log';

describe('Validate Util Functions', () => {
test('Logging', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/__utils/src/log.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Logger } from './logger';

export { LogLevel } from './logger';
Expand Down Expand Up @@ -62,6 +61,8 @@ function matchingUriLength(a: string, b: string): number {
const bParts = b.split(sep);
const limit = Math.min(aParts.length, bParts.length);
let i = 0;
for (i = 0; i < limit && aParts[i] === bParts[i]; i += 1) {}
while (i < limit && aParts[i] === bParts[i]) {
++i;
}
return aParts.slice(0, i).join(sep).length;
}
3 changes: 2 additions & 1 deletion packages/__utils/src/logFile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LoggerConnection } from './logger';
import { promises as fs } from 'fs';

import { LoggerConnection } from './logger';

type Level = 'ERR' | 'INF' | 'WRN' | 'LOG';
type Console = LoggerConnection['console'];

Expand Down
2 changes: 0 additions & 2 deletions packages/__utils/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */

export enum LogLevel {
NONE = 0,
ERROR,
Expand Down
18 changes: 7 additions & 11 deletions packages/__utils/src/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ export function measureExecution<T>(fn: () => T): MeasureResult<T> {
}

export async function measurePromiseExecution<T>(fn: () => Promise<T>): Promise<MeasureResult<T>> {
try {
const start = process.hrtime();
const r = await fn();
const elapsedTimeMs = hrTimeToMs(process.hrtime(start));
return {
elapsedTimeMs,
r,
};
} catch (e) {
throw e;
}
const start = process.hrtime();
const r = await fn();
const elapsedTimeMs = hrTimeToMs(process.hrtime(start));
return {
elapsedTimeMs,
r,
};
}

export function elapsedTimeMsFrom(relativeTo: [number, number]): number {
Expand Down
5 changes: 3 additions & 2 deletions packages/__utils/src/uriHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { cleanUri, isSupportedDoc, isSupportedUri, relativeTo, relativeToFile, toFileUri, toUri, uriToName } from './uriHelper';
import { URI as Uri, Utils as UriUtils } from 'vscode-uri';
import * as path from 'path';
import { URI as Uri, Utils as UriUtils } from 'vscode-uri';

import { cleanUri, isSupportedDoc, isSupportedUri, relativeTo, relativeToFile, toFileUri, toUri, uriToName } from './uriHelper';

const uri = Uri.file(__filename);

Expand Down
4 changes: 3 additions & 1 deletion packages/__utils/src/uriHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export function relativeTo(uriFrom: Uri, uriTo: Uri): string {
const fromSegments = splitUri(uriFrom);
const toSegments = splitUri(uriTo);
let i = 0;
for (i = 0; i < fromSegments.length && i < toSegments.length && fromSegments[i] === toSegments[i]; ++i) {}
for (i = 0; i < fromSegments.length && i < toSegments.length && fromSegments[i] === toSegments[i]; ++i) {
/* empty */
}
const prefix = '../'.repeat(fromSegments.length - i);
return (prefix + toSegments.slice(i).join('/')).replace(/\/$/, '');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/__utils/src/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unique, uniqueFilter, freqCount, mustBeDefined, isDefined, textToWords, pick, setIfDefined } from './util';
import { freqCount, isDefined, mustBeDefined, pick, setIfDefined, textToWords, unique, uniqueFilter } from './util';

describe('Util', () => {
test('unique', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/_integrationTests/.eslintrc.js

This file was deleted.

Loading

0 comments on commit 465e3f8

Please sign in to comment.