From 978ecede6921282efc0338b340672a323123ef4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=BA=E6=B0=91=E7=9A=84=E5=8B=A4=E5=8A=A1=E5=91=98?= Date: Tue, 24 Dec 2024 17:41:17 +0800 Subject: [PATCH] =?UTF-8?q?`eslint.config.mjs`=20=E2=86=92=20`eslint.confi?= =?UTF-8?q?g.js`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eslint.config.js | 109 ++++++++++++++++++++++++++++++++++++++++++++++ eslint.config.mjs | 69 ----------------------------- 2 files changed, 109 insertions(+), 69 deletions(-) create mode 100644 eslint.config.js delete mode 100644 eslint.config.mjs diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 000000000..2f9927a05 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,109 @@ +import js from '@eslint/js'; +import globals from 'globals'; +import importPlugin from 'eslint-plugin-import'; +import json from '@eslint/json'; +import markdown from '@eslint/markdown'; +import regexp from 'eslint-plugin-regexp'; +import stylisticJS from '@stylistic/eslint-plugin-js'; +import yml from 'eslint-plugin-yml'; + +export default [ + { + files: ['**/*.js', '**/*.mjs'], + ignores: ['.history/*'], + languageOptions: { + ecmaVersion: 'latest', + sourceType: 'script', + globals: { + ...globals.browser, + ...globals.greasemonkey, + ...globals.node, + chatgpt: 'readonly', + chrome: 'readonly', + config: 'writable', + CryptoJS: 'readonly', + dom: 'readonly', + GM_cookie: 'readonly', + hljs: 'readonly', + icons: 'writable', + ipv4: 'readonly', + marked: 'readonly', + modals: 'writable', + renderMathInElement: 'readonly', + settings: 'writable', + toggles: 'writable' + } + }, + plugins: { + import: importPlugin, + 'js-styles': stylisticJS, + regexp + }, + rules: { + ...js.configs.recommended.rules, + ...importPlugin.flatConfigs.recommended.rules, + ...regexp.configs['flat/recommended'].rules, + indent: 'off', + 'no-unexpected-multiline': 'off', + 'key-spacing': 'off', // allow whitespace anywhere + 'js-styles/no-trailing-spaces': 'off', // except at ends of lines + 'js-styles/max-len': [ + 'error', + { + code: 180, + ignoreComments: true, + ignoreStrings: true, + ignoreTemplateLiterals: true, + ignoreRegExpLiterals: true + } + ], + 'regexp/no-unused-capturing-group': 'off', + 'regexp/no-empty-group': 'off', + 'regexp/no-super-linear-backtracking': 'off', + 'regexp/no-empty-capturing-group': 'off', + 'regexp/no-useless-flag': 'off', + 'js-styles/no-extra-semi': 'error', // disallow unnecessary semicolons + quotes: ['error', 'single', { allowTemplateLiterals: true }], // enforce single quotes + 'comma-dangle': ['error', 'never'], // no trailing commas + 'no-async-promise-executor': 'off', + 'no-constant-condition': 'off', + 'no-empty': 'off', + 'no-inner-declarations': 'off', + 'no-useless-escape': 'off', + 'no-unused-vars': 'off', // allow unused vars + 'no-undef': 'off', // disable undefined vars check + 'no-irregular-whitespace': 'error', + 'no-misleading-character-class': 'off', + 'no-redeclare': 'off' + } + }, + { + files: ['**/*.mjs'], + languageOptions: { sourceType: 'module' } + }, + { + files: ['**/*.json'], + ignores: ['**/package-lock.json', '.history/*'], + languageOptions: { ...json.languageOptions }, + rules: { ...json.configs.recommended.rules } + }, + { + files: ['**/*.md'], + ignores: ['.history/*'], + languageOptions: { ...markdown.languageOptions }, + plugins: { markdown }, + rules: { + ...markdown.configs.recommended[0].rules, + 'markdown/heading-increment': 'off', + 'markdown/fenced-code-language': 'off', + 'markdown/no-missing-label-refs': 'off', + 'markdown/no-empty-links': 'off' + } + }, + { + files: ['**/*.yaml', '**/*.yml'], + ignores: ['.history/*'], + languageOptions: { ...yml.languageOptions }, + rules: { ...yml.configs['flat/standard'][1].rules } + } +]; diff --git a/eslint.config.mjs b/eslint.config.mjs deleted file mode 100644 index 92c370c2a..000000000 --- a/eslint.config.mjs +++ /dev/null @@ -1,69 +0,0 @@ -import js from '@eslint/js' -import globals from 'globals' -import importPlugin from 'eslint-plugin-import' -import json from '@eslint/json' -import markdown from '@eslint/markdown' -import regexp from 'eslint-plugin-regexp' -import stylisticJS from '@stylistic/eslint-plugin-js' -import yml from 'eslint-plugin-yml' - -export default [ - { - files: ['**/*.js', '**/*.mjs'], - ignores: ['.history/*'], - languageOptions: { - ecmaVersion: 'latest', sourceType: 'script', - globals: { - ...globals.browser, ...globals.greasemonkey, ...globals.node, chatgpt: 'readonly', chrome: 'readonly', - config: 'writable', CryptoJS: 'readonly', dom: 'readonly', GM_cookie: 'readonly', hljs: 'readonly', - icons: 'writable', ipv4: 'readonly', marked: 'readonly', modals: 'writable', - renderMathInElement: 'readonly', settings: 'writable', toggles: 'writable' - } - }, - plugins: { 'import': importPlugin, 'js-styles': stylisticJS, regexp }, - rules: { - ...js.configs.recommended.rules, - ...importPlugin.flatConfigs.recommended.rules, - ...regexp.configs['flat/recommended'].rules, - 'indent': 'off', 'no-unexpected-multiline': 'off', 'key-spacing': 'off', // allow whitespace anywhere - 'js-styles/no-trailing-spaces': 'off', // ...except at ends of lines - 'js-styles/max-len': ['error', { - 'code': 180, // limit lines to 120 chars except if containing... - 'ignoreComments': true, 'ignoreStrings': true, // ...trailing/own-line comments, quoted strings... - 'ignoreTemplateLiterals': true, 'ignoreRegExpLiterals': true - }], // ...or template/regex literals - 'regexp/no-unused-capturing-group': 'off', - 'regexp/no-empty-group': 'off', - 'regexp/no-super-linear-backtracking': 'off', - 'regexp/no-empty-capturing-group': 'off', - 'regexp/no-useless-flag': 'off', - 'js-styles/no-extra-semi': 'error', // disallow unnecessary semicolons - 'quotes': ['error', 'single', { 'allowTemplateLiterals': true }], // enforce single quotes except backticks to avoid escaping quotes - 'comma-dangle': ['error', 'never'], // enforce no trailing commas in arrays or objects - 'no-async-promise-executor': 'off', // allow promise executor functions to be async (to accomodate await lines) - 'no-constant-condition': 'off', // allow constant conditions - 'no-empty': 'off', // allow empty blocks - 'no-inner-declarations': 'off', // allow function declarations anywhere - 'no-useless-escape': 'off', // allow all escape chars cause ESLint sucks at detecting truly useless ones - // 'no-unused-vars': ['error', { 'caughtErrors': 'none' }], // allow unused named args in catch blocks - 'no-unused-vars': 'off', // 禁用未使用变量的检查 - 'no-undef': 'off', //禁用未定义变量的检查 - 'no-irregular-whitespace': 'error',// 启用不规则空白字符规则 - 'no-misleading-character-class': 'off', - 'no-redeclare': 'off' - } - }, - { files: ['**/*.mjs'], languageOptions: { sourceType: 'module' } }, - { files: ['**/*.json'], ignores: ['**/package-lock.json', '.history/*'], language: 'json/json', ...json.configs.recommended }, - { - files: ['**/*.md'], ignores: ['.history/*'], language: 'markdown/commonmark', plugins: { markdown }, - rules: { - ...markdown.configs.recommended[0].rules, - 'markdown/heading-increment': 'off', // allow headings to skip levels - 'markdown/fenced-code-language': 'off', // allow code blocks w/ no language specified - 'markdown/no-missing-label-refs': 'off', // allow missing label references - 'markdown/no-empty-links': 'off' // allow empty links - } - }, - { files: ['**/*.yaml, **/*.yml'], ignores: ['.history/*'], ...yml.configs['flat/standard'][1] } -] \ No newline at end of file