chore: update ESLint to v9

This commit is contained in:
fisker
2025-03-19 03:57:52 +08:00
committed by RedHoodSu
parent 81ee39e720
commit b88f8e552c
11 changed files with 62 additions and 44 deletions

View File

@@ -1,20 +0,0 @@
module.exports = {
parser: 'babel-eslint',
env: {
browser: true,
commonjs: true,
es6: true,
},
extends: 'eslint:recommended',
parserOptions: {
sourceType: 'module',
},
globals: {
VERSION: true,
ENV: true,
},
rules: {
quotes: ['error', 'single'],
'prefer-const': 2,
},
}

View File

@@ -4,6 +4,7 @@ const clean = require('postcss-clean')
const webpack = require('webpack') const webpack = require('webpack')
const pkg = require('../package.json') const pkg = require('../package.json')
const path = require('path') const path = require('path')
const ESLintPlugin = require('eslint-webpack-plugin');
process.traceDeprecation = true process.traceDeprecation = true
@@ -34,8 +35,6 @@ module.exports = {
entry: './src/index', entry: './src/index',
resolve: { resolve: {
symlinks: false, symlinks: false,
},
resolve: {
alias: { alias: {
axios: path.resolve(__dirname, '../src/lib/empty.js'), axios: path.resolve(__dirname, '../src/lib/empty.js'),
micromark: path.resolve(__dirname, '../src/lib/micromark.js'), micromark: path.resolve(__dirname, '../src/lib/micromark.js'),
@@ -82,7 +81,6 @@ module.exports = {
], ],
}, },
}, },
'eslint-loader',
], ],
}, },
{ {
@@ -105,5 +103,6 @@ module.exports = {
new webpack.DefinePlugin({ new webpack.DefinePlugin({
VERSION: '"' + pkg.version + '"', VERSION: '"' + pkg.version + '"',
}), }),
new ESLintPlugin()
], ],
} }

34
eslint.config.mjs Normal file
View File

@@ -0,0 +1,34 @@
import babelEslintParser from '@babel/eslint-parser'
import eslintJs from '@eslint/js'
import globals from 'globals'
export default [
eslintJs.configs.recommended,
{
languageOptions: {
parser: babelEslintParser,
parserOptions: {
requireConfigFile: false,
babelOptions: {
babelrc: false,
configFile: false,
},
},
globals: {
...globals.builtin,
...globals.browser,
...globals.commonjs,
VERSION: true,
ENV: true,
},
},
rules: {
quotes: ['error', 'single', { 'avoidEscape': true, 'allowTemplateLiterals': false }],
'prefer-const': 2,
},
},
{files: ['build/**/*.js'], languageOptions:{globals: {...globals.node}}},
{
ignores: ['test','dist','coverage'],
}
]

View File

@@ -14,7 +14,7 @@
"dev": "webpack-dev-server --config build/webpack.dev.js --host 0.0.0.0", "dev": "webpack-dev-server --config build/webpack.dev.js --host 0.0.0.0",
"test": "karma start", "test": "karma start",
"format": "lsla prettier \"*.{js,ts}\" \"src/**/*.{js,scss,css}\" \"build/*.js\" \"test/*.{js,html}\" --write", "format": "lsla prettier \"*.{js,ts}\" \"src/**/*.{js,scss,css}\" \"build/*.js\" \"test/*.{js,html}\" --write",
"lint": "eslint src/**/*.js", "lint": "eslint .",
"lint:fix": "npm run lint -- --fix", "lint:fix": "npm run lint -- --fix",
"es5": "es-check es5 dist/eruda.js dist/eruda-polyfill.js", "es5": "es-check es5 dist/eruda.js dist/eruda-polyfill.js",
"setup": "lsla shx mkdir -p test/lib && lsla shx cp node_modules/jasmine-core/lib/jasmine-core/{jasmine.css,jasmine.js,jasmine-html.js,boot.js} test/lib && lsla shx cp node_modules/jasmine-jquery/lib/jasmine-jquery.js test/lib && lsla shx cp node_modules/jquery/dist/jquery.js test/lib", "setup": "lsla shx mkdir -p test/lib && lsla shx cp node_modules/jasmine-core/lib/jasmine-core/{jasmine.css,jasmine.js,jasmine-html.js,boot.js} test/lib && lsla shx cp node_modules/jasmine-jquery/lib/jasmine-jquery.js test/lib && lsla shx cp node_modules/jquery/dist/jquery.js test/lib",
@@ -37,20 +37,22 @@
"homepage": "https://eruda.liriliri.io/", "homepage": "https://eruda.liriliri.io/",
"devDependencies": { "devDependencies": {
"@babel/core": "^7.18.6", "@babel/core": "^7.18.6",
"@babel/eslint-parser": "^7.26.10",
"@babel/plugin-proposal-class-properties": "^7.18.6", "@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-transform-runtime": "^7.18.6", "@babel/plugin-transform-runtime": "^7.18.6",
"@babel/preset-env": "^7.18.6", "@babel/preset-env": "^7.18.6",
"@babel/runtime": "^7.18.6", "@babel/runtime": "^7.18.6",
"@eslint/js": "^9.22.0",
"@jsdevtools/coverage-istanbul-loader": "^3.0.5", "@jsdevtools/coverage-istanbul-loader": "^3.0.5",
"autoprefixer": "^9.7.4", "autoprefixer": "^9.7.4",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.5", "babel-loader": "^8.2.5",
"chobitsu": "^1.8.4", "chobitsu": "^1.8.4",
"core-js": "^3.37.1", "core-js": "^3.37.1",
"css-loader": "^3.4.2", "css-loader": "^3.4.2",
"es-check": "^6.2.1", "es-check": "^6.2.1",
"eslint": "^6.8.0", "eslint": "^9.22.0",
"eslint-loader": "^3.0.3", "eslint-webpack-plugin": "^5.0.0",
"globals": "^16.0.0",
"jasmine-core": "^2.99.1", "jasmine-core": "^2.99.1",
"jasmine-jquery": "^2.1.1", "jasmine-jquery": "^2.1.1",
"jquery": "^3.4.1", "jquery": "^3.4.1",

View File

@@ -43,7 +43,7 @@ export default class CssStore {
try { try {
// Started with version 64, Chrome does not allow cross origin script to access this property. // Started with version 64, Chrome does not allow cross origin script to access this property.
if (!styleSheet.cssRules) return if (!styleSheet.cssRules) return
} catch (e) { } catch {
return return
} }
@@ -53,8 +53,9 @@ export default class CssStore {
// Mobile safari will throw DOM Exception 12 error, need to try catch it. // Mobile safari will throw DOM Exception 12 error, need to try catch it.
try { try {
matchesEl = this._elMatchesSel(cssRule.selectorText) matchesEl = this._elMatchesSel(cssRule.selectorText)
/* eslint-disable no-empty */ } catch {
} catch (e) {} // No op
}
if (!matchesEl) return if (!matchesEl) return

View File

@@ -261,8 +261,9 @@ export default class Elements extends Tool {
try { try {
const { node } = chobitsu.domain('DOM').getNode({ nodeId: backendNodeId }) const { node } = chobitsu.domain('DOM').getNode({ nodeId: backendNodeId })
this.select(node) this.select(node)
/* eslint-disable no-empty */ } catch {
} catch (e) {} // No op
}
} }
_setNode = (node) => { _setNode = (node) => {
if (node === this._curNode) return if (node === this._curNode) return

View File

@@ -18,7 +18,6 @@ export function curlStr(request) {
if (platform === 'windows') { if (platform === 'windows') {
platform = 'win' platform = 'win'
} }
/* eslint-disable */
let command = [] let command = []
const ignoredHeaders = arrToMap([ const ignoredHeaders = arrToMap([
'accept-encoding', 'accept-encoding',
@@ -36,7 +35,7 @@ export function curlStr(request) {
str str
.replace(/\\/g, '\\\\') .replace(/\\/g, '\\\\')
.replace(/"/g, '\\"') .replace(/"/g, '\\"')
.replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&') .replace(/[^a-zA-Z0-9\s_\-:=+~'/.',?;()*`&]/g, '^$&')
.replace(/%(?=[a-zA-Z0-9_])/g, '%^') .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
.replace(/\r?\n/g, '^\n\n') + .replace(/\r?\n/g, '^\n\n') +
encapsChars encapsChars
@@ -54,14 +53,16 @@ export function curlStr(request) {
return '\\u' + hexString return '\\u' + hexString
} }
if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) { // eslint-disable-next-line no-control-regex
if (/[\0-\x1F\x7F-\x9F!]|'/.test(str)) {
return ( return (
"$'" + "$'" +
str str
.replace(/\\/g, '\\\\') .replace(/\\/g, '\\\\')
.replace(/\'/g, "\\'") .replace(/'/g, "\\'")
.replace(/\n/g, '\\n') .replace(/\n/g, '\\n')
.replace(/\r/g, '\\r') .replace(/\r/g, '\\r')
// eslint-disable-next-line no-control-regex
.replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) + .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
"'" "'"
) )

View File

@@ -147,7 +147,7 @@ export default class Cookie {
try { try {
showSources('object', JSON.parse(val)) showSources('object', JSON.parse(val))
} catch (e) { } catch {
showSources('raw', val) showSources('raw', val)
} }
}) })

View File

@@ -174,7 +174,7 @@ export default class Storage {
try { try {
showSources('object', JSON.parse(val)) showSources('object', JSON.parse(val))
} catch (e) { } catch {
showSources('raw', val) showSources('raw', val)
} }
}) })

View File

@@ -220,8 +220,9 @@ export default class Sources extends Tool {
if (isStr(val)) { if (isStr(val)) {
val = JSON.parse(val) val = JSON.parse(val)
} }
/* eslint-disable no-empty */ } catch {
} catch (e) {} // No op
}
const objViewer = new LunaObjectViewer( const objViewer = new LunaObjectViewer(
this._$el.find('.eruda-json').get(0), this._$el.find('.eruda-json').get(0),

View File

@@ -34,7 +34,6 @@ export function hasSafeArea() {
} }
export function escapeJsonStr(str) { export function escapeJsonStr(str) {
/* eslint-disable quotes */
return escapeJsStr(str).replace(/\\'/g, "'").replace(/\t/g, '\\t') return escapeJsStr(str).replace(/\\'/g, "'").replace(/\t/g, '\\t')
} }
@@ -59,7 +58,7 @@ export function safeStorage(type, memReplacement) {
const y = ret.getItem(x) const y = ret.getItem(x)
ret.removeItem(x) ret.removeItem(x)
if (y !== x) throw new Error() if (y !== x) throw new Error()
} catch (e) { } catch {
if (memReplacement) return memStorage if (memReplacement) return memStorage
return return
} }
@@ -116,7 +115,7 @@ export function classPrefix(str) {
} }
}) })
return html.stringify(tree) return html.stringify(tree)
} catch (e) { } catch {
return processClass(str) return processClass(str)
} }
} }
@@ -135,7 +134,7 @@ function traverseTree(tree, handler) {
} }
function processClass(str) { function processClass(str) {
const prefix = `eruda-` const prefix = 'eruda-'
return map(trim(str).split(/\s+/), (singleClass) => { return map(trim(str).split(/\s+/), (singleClass) => {
if (contain(singleClass, prefix)) { if (contain(singleClass, prefix)) {