From 1c545dca14f7757942fecf82a0e48070ba523219 Mon Sep 17 00:00:00 2001 From: Ziwei Wang Date: Tue, 27 Aug 2024 17:58:37 -0400 Subject: [PATCH] Update: use eslint flat config .eslintrc.js and .eslintignore are deprecated and the new flat config system is preferred. The CLI also doesn't support --ext flag with the flat config system. How the new config is generated: https://eslint.org/docs/latest/use/configure/migration-guide#migrate-your-config-file Reference for cli flag changes: https://eslint.org/docs/latest/use/configure/migration-guide#cli-flag-changes --- .eslintignore | 2 -- .eslintrc.js | 43 --------------------------- eslint.config.mjs | 75 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 76 insertions(+), 46 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.js create mode 100644 eslint.config.mjs diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 27a03425..00000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -.eslintrc.js -jest.config.js \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index e43e0646..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,43 +0,0 @@ -module.exports = { - env: { - browser: true, - es2021: true - }, - extends: [ - 'standard-with-typescript', - 'plugin:deprecation/recommended' - ], - overrides: [ - { - env: { - node: true - }, - files: [ - '*.ts' - ], - parserOptions: { - sourceType: 'script' - } - } - ], - parserOptions: { - ecmaVersion: 'latest', - sourceType: 'module' - }, - plugins: ['header'], - rules: { - "header/header": [2, "block", [ - " --------------------------------------------------------------------------------------------", - {"pattern": " \\* Copyright \\(c\\) .*\\. All rights reserved\\.", "template": " * Copyright (c) 2023 Savoir-faire Linux. All rights reserved."}, - " * Licensed under the MIT License. See License.txt in the project root for license information.", - " * ------------------------------------------------------------------------------------------ ", - ], 2] - }, - ignorePatterns: [ - 'out', - 'poky', - '.vscode-test', - 'client/server', - '__mocks__/vscode.ts' - ], -} diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 00000000..69486db6 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,75 @@ +import header from "eslint-plugin-header"; +import globals from "globals"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import js from "@eslint/js"; +import { FlatCompat } from "@eslint/eslintrc"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all, +}); + +export default [ + { + ignores: [ + "**/out", + "**/poky", + "**/.vscode-test", + "__mocks__/vscode.ts", + "**/jest.config.js", + "**/eslint.config.mjs", + ], + }, + ...compat.extends( + "standard-with-typescript", + "plugin:deprecation/recommended" + ), + { + plugins: { + header, + }, + + languageOptions: { + globals: { + ...globals.browser, + }, + + ecmaVersion: "latest", + sourceType: "module", + }, + + rules: { + "header/header": [ + 2, + "block", + [ + " --------------------------------------------------------------------------------------------", + { + pattern: " \\* Copyright \\(c\\) .*\\. All rights reserved\\.", + template: + " * Copyright (c) 2023 Savoir-faire Linux. All rights reserved.", + }, + " * Licensed under the MIT License. See License.txt in the project root for license information.", + " * ------------------------------------------------------------------------------------------ ", + ], + 2, + ], + }, + }, + { + files: ["**/*.ts"], + + languageOptions: { + globals: { + ...globals.node, + }, + + ecmaVersion: 5, + sourceType: "commonjs", + }, + }, +]; diff --git a/package.json b/package.json index 8e0f08c9..22910017 100644 --- a/package.json +++ b/package.json @@ -894,7 +894,7 @@ "clean:client": "rm -fr ./client/node_modules ./client/out client/tsconfig.tsbuildinfo client/.vscode-test", "clean:lib": "rm -fr ./lib/node_modules", "clean": "npm run clean:lib && npm run clean:server && npm run clean:client && rm -fr node_modules integration-tests/out integration-tests/project-folder/build* .vscode-test .eslintcache resources coverage ./out *.vsix", - "lint": "eslint . --ext js,ts --cache", + "lint": "eslint . --cache", "jest": "jest", "test": "npm run jest && npm run test:integration && npm run test:grammar", "test:integration": "xvfb-run node ./integration-tests/out/runTest.js",