diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 7895dad..0000000 --- a/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -test/XMLHttpRequest.cjs diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 774eb47..1a4846b 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -24,6 +24,7 @@ jobs: node-version: ${{ matrix.node-version }} - run: npm ci - run: npm i ol@${{ matrix.ol-version }} + - run: npm run lint - run: npm run build - run: npm test diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..fcaa29c --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,81 @@ +import mocha from 'eslint-plugin-mocha'; +import globals from 'globals'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import js from '@eslint/js'; +import { FlatCompat } from '@eslint/eslintrc'; + +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 [{ + ignores: ['test/XMLHttpRequest.cjs'], +}, +...compat.extends( + 'eslint:recommended', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', +).map(config => ({ + ...config, + files: ['**/*.ts'], +})), +{ + plugins: { + mocha, + }, + + languageOptions: { + globals: { + ...globals.browser, + ...globals.commonjs, + ...globals.node, + ...globals.mocha, + }, + + ecmaVersion: 2017, + sourceType: 'module', + }, + + rules: { + 'no-unused-vars': 'off', + + '@typescript-eslint/no-unused-vars': ['warn', { + argsIgnorePattern: '^_', + varsIgnorePattern: '^_', + caughtErrorsIgnorePattern: '^_', + }], + + quotes: ['error', 'single'], + semi: ['error', 'always'], + 'mocha/no-exclusive-tests': 'error', + }, + + files: ['**/*.ts'], +}, +...compat.extends('eslint:recommended').map(config => ({ + ...config, + files: ['**/*.js', '**/*.cjs'], +})), +{ + files: ['test/*.ts'], + + rules: { + '@typescript-eslint/no-unused-expressions': 'off', + }, +}, +{ + files: ['**/*.cjs'], + + languageOptions: { + sourceType: 'commonjs', + }, + + rules: { + '@typescript-eslint/no-require-imports': 'off' + }, +}]; diff --git a/package-lock.json b/package-lock.json index 738e69b..c7c428f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,8 @@ "sqlite-wasm-http": "^1.2.0" }, "devDependencies": { + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "^9.11.0", "@rollup/plugin-typescript": "^11.1.5", "@types/chai": "^4.3.11", "@types/chai-spies": "^1.0.6", @@ -36,6 +38,7 @@ "eslint": "^9.8.0", "eslint-plugin-mocha": "^10.2.0", "gh-pages": "^6.1.1", + "globals": "^15.9.0", "html-loader": "^5.0.0", "html-webpack-plugin": "^5.6.0", "link": "^2.1.0", @@ -60,7 +63,7 @@ "node": ">=18.0.0" }, "peerDependencies": { - "ol": ">=10.0.0<10.3.0" + "ol": ">=10.0.0 <10.3.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -3788,6 +3791,21 @@ "eslint": ">=7.0.0" } }, + "node_modules/eslint-plugin-mocha/node_modules/globals": { + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "dev": true, + "dependencies": { + "type-fest": "^0.20.2" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -4587,15 +4605,12 @@ "dev": true }, "node_modules/globals": { - "version": "13.24.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", - "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "version": "15.9.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.9.0.tgz", + "integrity": "sha512-SmSKyLLKFbSr6rptvP8izbyxJL4ILwqO9Jg23UA0sDlGlu58V59D1//I3vlc0KJphVdUR7vMjHIplYnzBxorQA==", "dev": true, - "dependencies": { - "type-fest": "^0.20.2" - }, "engines": { - "node": ">=8" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" diff --git a/package.json b/package.json index 1b378a0..055535b 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,8 @@ "ol": ">=10.0.0 <10.3.0" }, "devDependencies": { + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "^9.11.0", "@rollup/plugin-typescript": "^11.1.5", "@types/chai": "^4.3.11", "@types/chai-spies": "^1.0.6", @@ -69,6 +71,7 @@ "eslint": "^9.8.0", "eslint-plugin-mocha": "^10.2.0", "gh-pages": "^6.1.1", + "globals": "^15.9.0", "html-loader": "^5.0.0", "html-webpack-plugin": "^5.6.0", "link": "^2.1.0",