Skip to content

Commit

Permalink
chore: update ESLint to v9 and switch to flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed May 14, 2024
1 parent 2bbaba4 commit 9aa392f
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 137 deletions.
25 changes: 0 additions & 25 deletions .eslintrc

This file was deleted.

52 changes: 52 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import js from '@eslint/js';
import globals from 'globals';

/** @type {import('eslint').Linter.FlatConfig[]} */
export default [
// global ignores
{
ignores: [
'.yarn/**',
'node_modules/**',
'dist/**',
'test/regression-fixtures/**',
'test/regression-diffs/**',
'test/cli/output/**',
'coverage/**',
],
},
{
languageOptions: {
ecmaVersion: 2021,
sourceType: 'module',
globals: {
...globals.nodeBuiltin,
},
},
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
},
js.configs.recommended,
{
files: ['**/*.js', '**/*.mjs'],
rules: {
strict: 'error',
},
},
{
files: ['**/*.cjs'],
languageOptions: {
sourceType: 'commonjs',
},
},
{
files: ['**/*.test.js'],
languageOptions: {
sourceType: 'module',
globals: {
...globals.jest,
},
},
},
];
2 changes: 1 addition & 1 deletion lib/svgo-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const loadConfig = async (configFile, cwd = process.cwd()) => {
}
}
let dir = cwd;
// eslint-disable-next-line no-constant-condition

while (true) {
const js = path.join(dir, 'svgo.config.js');
if (await isFile(js)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/svgo/coa.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const regSVGFile = /\.svg$/i;
export function checkIsDir(filePath) {
try {
return fs.lstatSync(filePath).isDirectory();
} catch (e) {
} catch {
return filePath.endsWith(path.sep);
}
}
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
},
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules jest --maxWorkers=4 --coverage",
"lint": "eslint --ignore-path .gitignore . && prettier --check . --ignore-path .gitignore",
"fix": "eslint --ignore-path .gitignore --fix . && prettier --write . --ignore-path .gitignore",
"lint": "eslint . && prettier --check . --ignore-path .gitignore",
"fix": "eslint --fix . && prettier --write . --ignore-path .gitignore",
"typecheck": "tsc",
"generate-bundles": "rollup -c",
"test-bundles": "yarn generate-bundles && node ./test/svgo.cjs && node ./test/browser.js",
Expand All @@ -110,14 +110,16 @@
"picocolors": "^1.0.0"
},
"devDependencies": {
"@eslint/js": "^9.2.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@types/css-tree": "^2.3.7",
"@types/csso": "^5.0.4",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.11",
"eslint": "^8.57.0",
"eslint": "^9.2.0",
"globals": "^14.0.0",
"jest": "^29.7.0",
"node-fetch": "^2.7.0",
"pixelmatch": "^5.3.0",
Expand Down
2 changes: 1 addition & 1 deletion plugins/_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const intersects = function (path1, path2) {
direction = minus(simplex[0]); // set the direction to point towards the origin

var iterations = 1e4; // infinite loop protection, 10 000 iterations is more than enough
// eslint-disable-next-line no-constant-condition

while (true) {
if (iterations-- == 0) {
console.error(
Expand Down
2 changes: 1 addition & 1 deletion plugins/inlineStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const fn = (root, params) => {
matchedElements.push(node);
}
}
} catch (selectError) {
} catch {
continue;
}
// nothing selected
Expand Down
2 changes: 1 addition & 1 deletion test/regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const runTests = async (list) => {
let file;
try {
file = await fs.readFile(path.join(fixturesDir, name), 'utf-8');
} catch (error) {
} catch {
res.statusCode = 404;
res.end();
return;
Expand Down
Loading

0 comments on commit 9aa392f

Please sign in to comment.