mirror of
https://github.com/klinecharts/KLineChart.git
synced 2024-11-25 16:22:43 +08:00
ci: upgrade eslint
This commit is contained in:
parent
bb1764ab33
commit
5af6ce0661
@ -22,7 +22,8 @@ export default [
|
|||||||
"@typescript-eslint/no-non-null-assertion": "off",
|
"@typescript-eslint/no-non-null-assertion": "off",
|
||||||
"@typescript-eslint/class-methods-use-this": "off",
|
"@typescript-eslint/class-methods-use-this": "off",
|
||||||
"@typescript-eslint/max-params": "off",
|
"@typescript-eslint/max-params": "off",
|
||||||
"@typescript-eslint/no-magic-numbers": "off"
|
"@typescript-eslint/no-magic-numbers": "off",
|
||||||
|
"@typescript-eslint/prefer-destructuring": "off"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -60,7 +60,6 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/standalone": "^7.24.4",
|
"@babel/standalone": "^7.24.4",
|
||||||
"@rollup/plugin-commonjs": "^25.0.7",
|
"@rollup/plugin-commonjs": "^25.0.7",
|
||||||
"@rollup/plugin-eslint": "^9.0.5",
|
|
||||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||||
"@rollup/plugin-replace": "^5.0.5",
|
"@rollup/plugin-replace": "^5.0.5",
|
||||||
"@rollup/plugin-terser": "^0.4.4",
|
"@rollup/plugin-terser": "^0.4.4",
|
||||||
@ -73,8 +72,8 @@
|
|||||||
"codesandbox": "^2.2.3",
|
"codesandbox": "^2.2.3",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"dts-bundle-generator": "^9.5.1",
|
"dts-bundle-generator": "^9.5.1",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^9.13.0",
|
||||||
"eslint-config-love": "^87.0.0",
|
"eslint-config-love": "^89.0.1",
|
||||||
"eslint-plugin-file-progress": "^1.5.0",
|
"eslint-plugin-file-progress": "^1.5.0",
|
||||||
"fs-extra": "^11.2.0",
|
"fs-extra": "^11.2.0",
|
||||||
"gh-pages": "^6.1.1",
|
"gh-pages": "^6.1.1",
|
||||||
|
@ -3,56 +3,55 @@ import { createFilter } from '@rollup/pluginutils';
|
|||||||
import { loadESLint } from 'eslint';
|
import { loadESLint } from 'eslint';
|
||||||
|
|
||||||
function normalizePath(id) {
|
function normalizePath(id) {
|
||||||
return relative(process.cwd(), id).split(sep).join('/');
|
return relative(process.cwd(), id).split(sep).join('/');
|
||||||
}
|
}
|
||||||
async function eslint(options = {}) {
|
async function eslint(options = {}) {
|
||||||
if (typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
const configFile = resolve(process.cwd(), options);
|
const configFile = resolve(process.cwd(), options);
|
||||||
options = require(configFile);
|
options = require(configFile);
|
||||||
options.useEslintrc = true;
|
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 };
|
export { eslint as default };
|
||||||
|
Loading…
Reference in New Issue
Block a user