Skip to content

Commit

Permalink
chore: update ESLint to v9 and switch to flat config (svg#2001)
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR authored May 26, 2024
1 parent 83bfee4 commit 4daaa42
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 152 deletions.
25 changes: 0 additions & 25 deletions .eslintrc

This file was deleted.

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

/**
* @typedef {import('eslint').Linter.FlatConfig} FlatConfig
*/

/** @type {FlatConfig[]} */
export default [
{
ignores: [
'.yarn/**',
'node_modules/**',
'dist/**',
'test/regression-fixtures/**',
'test/regression-diffs/**',
'test/cli/output/**',
'coverage/**',
],
},
{
languageOptions: {
ecmaVersion: 2021,
globals: {
...globals.nodeBuiltin,
},
},
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
},
js.configs.recommended,
{
files: ['**/*.js', '**/*.mjs'],
rules: {
strict: 'error',
},
},
{
files: ['**/*.test.js'],
languageOptions: {
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
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
},
"scripts": {
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --maxWorkers=4 --coverage",
"lint": "eslint --ignore-path .gitignore . && prettier --check .",
"fix": "eslint --ignore-path .gitignore --fix . && prettier --write .",
"lint": "eslint . && prettier --check .",
"fix": "eslint --fix . && prettier --write .",
"typecheck": "tsc",
"generate-bundles": "rollup -c",
"test-bundles": "yarn generate-bundles && node ./test/svgo.cjs && node ./test/browser.js",
Expand All @@ -110,6 +110,7 @@
"picocolors": "^1.0.0"
},
"devDependencies": {
"@eslint/js": "^9.3.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
Expand All @@ -118,13 +119,14 @@
"@types/jest": "^29.5.12",
"@types/node": "^20.12.11",
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
"eslint": "^9.3.0",
"globals": "^14.0.0",
"jest": "^29.7.0",
"pixelmatch": "^5.3.0",
"playwright": "^1.44.0",
"pngjs": "^7.0.0",
"prettier": "^3.2.5",
"rimraf": "^3.0.2",
"rimraf": "^5.0.7",
"rollup": "^4.17.2",
"tar-stream": "^3.1.7",
"typescript": "^5.4.5"
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 @@ -104,7 +104,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 4daaa42

Please sign in to comment.