Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade the eslint lib to v9 #570

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions .eslintrc.js

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/eslint-version-compatibility.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ESLint Compatibility Tests

on: [push, pull_request]

jobs:
eslint-test:
runs-on: ubuntu-latest

strategy:
matrix:
eslint-version: [8, 9] # Test with ESLint v8 and v9

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '22'

- name: Install dependencies
run: npm ci

- name: Install Specific ESLint Version
run: npm install eslint@${{ matrix.eslint-version }} # Install ESLint based on matrix version

- name: Run Tests
run: npm run test
Fixed Show fixed Hide fixed
44 changes: 44 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {FlatCompat} from '@eslint/eslintrc'
import js from '@eslint/js'
import eslintPlugin from 'eslint-plugin-eslint-plugin'
import globals from 'globals'
import path from 'node:path'
import {fileURLToPath} from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})

export default [
...compat.extends('./lib/configs/recommended.js', 'plugin:eslint-plugin/all'),
{
plugins: {
'eslint-plugin': eslintPlugin,
},

languageOptions: {
globals: {
...globals.node,
},

ecmaVersion: 2022,
sourceType: 'module',
},

rules: {
'import/extensions': 'off',
'import/no-commonjs': 'off',
'filenames/match-regex': 'off',
'i18n-text/no-en': 'off',
'eslint-plugin/prefer-placeholders': 'off',
'eslint-plugin/test-case-shorthand-strings': 'off',
'eslint-plugin/require-meta-docs-url': 'off',
'prettier/prettier': 'off',
'no-unused-vars': 'off',
},
},
]
9 changes: 6 additions & 3 deletions lib/rules/async-currenttarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ module.exports = {
const scopeDidWait = new WeakSet()

return {
AwaitExpression() {
scopeDidWait.add(context.getScope(), true)
AwaitExpression(node) {
const sourceCode = context.sourceCode
const scope = sourceCode.getScope(node)
scopeDidWait.add(scope, true)
},
MemberExpression(node) {
if (node.property && node.property.name === 'currentTarget') {
const scope = context.getScope()
const sourceCode = context.sourceCode
const scope = sourceCode.getScope(node)
if (scope.block.async && scopeDidWait.has(scope)) {
context.report({node, message: 'event.currentTarget inside an async function is error prone'})
}
Expand Down
10 changes: 7 additions & 3 deletions lib/rules/async-preventdefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ module.exports = {
const scopeDidWait = new WeakSet()

return {
AwaitExpression() {
scopeDidWait.add(context.getScope(), true)
AwaitExpression(node) {
const sourceCode = context.sourceCode
const scope = sourceCode.getScope(node)

scopeDidWait.add(scope, true)
},
CallExpression(node) {
if (node.callee.property && node.callee.property.name === 'preventDefault') {
const scope = context.getScope()
const sourceCode = context.sourceCode
const scope = sourceCode.getScope(node)
if (scope.block.async && scopeDidWait.has(scope)) {
context.report({node, message: 'event.preventDefault() inside an async function is error prone'})
}
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/no-implicit-buggy-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ module.exports = {

create(context) {
return {
Program() {
const scope = context.getScope()
Program(node) {
const sourceCode = context.sourceCode
const scope = sourceCode.getScope(node)

for (const variable of scope.variables) {
if (variable.writeable) {
Expand Down
Loading
Loading