diff --git a/eslint.config.js b/eslint.config.js index 5564f543..7f8bd448 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -22,7 +22,8 @@ export default [ "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/class-methods-use-this": "off", "@typescript-eslint/max-params": "off", - "@typescript-eslint/no-magic-numbers": "off" + "@typescript-eslint/no-magic-numbers": "off", + "@typescript-eslint/prefer-destructuring": "off" } } ] diff --git a/package.json b/package.json index e0d27a9e..995874a4 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,6 @@ "devDependencies": { "@babel/standalone": "^7.24.4", "@rollup/plugin-commonjs": "^25.0.7", - "@rollup/plugin-eslint": "^9.0.5", "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", @@ -73,8 +72,8 @@ "codesandbox": "^2.2.3", "cross-env": "^7.0.3", "dts-bundle-generator": "^9.5.1", - "eslint": "^8.57.0", - "eslint-config-love": "^87.0.0", + "eslint": "^9.13.0", + "eslint-config-love": "^89.0.1", "eslint-plugin-file-progress": "^1.5.0", "fs-extra": "^11.2.0", "gh-pages": "^6.1.1", diff --git a/scripts/eslint.js b/scripts/eslint.js index 61fd73a5..600aa44e 100644 --- a/scripts/eslint.js +++ b/scripts/eslint.js @@ -3,56 +3,55 @@ import { createFilter } from '@rollup/pluginutils'; import { loadESLint } from 'eslint'; function normalizePath(id) { - return relative(process.cwd(), id).split(sep).join('/'); + return relative(process.cwd(), id).split(sep).join('/'); } async function eslint(options = {}) { - if (typeof options === 'string') { - const configFile = resolve(process.cwd(), options); - options = require(configFile); - options.useEslintrc = true; + if (typeof options === 'string') { + const configFile = resolve(process.cwd(), options); + options = require(configFile); + options.useEslintrc = true; + } + const { include, exclude = /node_modules/, throwOnWarning = false, throwOnError = false, formatter = 'stylish', ...eslintOptions } = options; + + const ESLint = await loadESLint({ useFlatConfig: true }) + + const eslintInstance = new ESLint(eslintOptions); + const filter = createFilter(include, exclude); + return { + name: 'eslint', + async transform(_, id) { + const file = normalizePath(id); + if (!filter(id) || (await eslintInstance.isPathIgnored(file))) { + return null; + } + const results = await eslintInstance.lintFiles(file); + const [result] = results; + if (eslintOptions.fix) { + await ESLint.outputFixes(results); + } + if (result.warningCount === 0 && result.errorCount === 0) { + return null; + } + const eslintFormatter = typeof formatter === 'string' + ? await eslintInstance.loadFormatter(formatter) + : { format: formatter }; + const output = await eslintFormatter.format(results); + if (output) { + console.log(output); + } + const errorMessages = []; + if (result.warningCount > 0 && throwOnWarning) { + errorMessages.push(`${result.warningCount} warning${result.warningCount > 1 ? 's' : ''}`); + } + if (result.errorCount > 0 && throwOnError) { + errorMessages.push(`${result.errorCount} error${result.errorCount > 1 ? 's' : ''}`); + } + if (errorMessages.length > 0) { + throw new Error(`Found ${errorMessages.join(' and ')} in ${relative('.', result.filePath)}`); + } + return null; } - const { include, exclude = /node_modules/, throwOnWarning = false, throwOnError = false, formatter = 'stylish', ...eslintOptions } = options; - - const ESLint = await loadESLint({ useFlatConfig: true }) - - const eslintInstance = new ESLint(eslintOptions); - const filter = createFilter(include, exclude); - return { - name: 'eslint', - async transform(_, id) { - const file = normalizePath(id); - if (!filter(id) || (await eslintInstance.isPathIgnored(file))) { - return null; - } - const results = await eslintInstance.lintFiles(file); - const [result] = results; - if (eslintOptions.fix) { - await ESLint.outputFixes(results); - } - if (result.warningCount === 0 && result.errorCount === 0) { - return null; - } - const eslintFormatter = typeof formatter === 'string' - ? await eslintInstance.loadFormatter(formatter) - : { format: formatter }; - const output = await eslintFormatter.format(results); - if (output) { - // eslint-disable-next-line no-console - console.log(output); - } - const errorMessages = []; - if (result.warningCount > 0 && throwOnWarning) { - errorMessages.push(`${result.warningCount} warning${result.warningCount > 1 ? 's' : ''}`); - } - if (result.errorCount > 0 && throwOnError) { - errorMessages.push(`${result.errorCount} error${result.errorCount > 1 ? 's' : ''}`); - } - if (errorMessages.length > 0) { - throw new Error(`Found ${errorMessages.join(' and ')} in ${relative('.', result.filePath)}`); - } - return null; - } - }; + }; } export { eslint as default };