diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 913ad29..0000000 --- a/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -test/browser/build/* diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 5aaf283..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "env": { - "mocha": true, - "shared-node-browser": true, - "es2020": true - }, - "extends": [ - "eslint:recommended" - ], - "rules": { - "semi": [ - 2, - "always" - ], - "quotes": [ - "error", - "single" - ] - }, - "plugins": [ - "mocha" - ], - "globals": { - "__karma__": true, - "process": true - }, - "parserOptions": { - "ecmaVersion": 2020, - "sourceType": "module" - }, - "overrides": [ - { - "files": [ - "test/*.ts" - ], - "parser": "@typescript-eslint/parser", - "plugins": [ - "@typescript-eslint" - ], - "rules": { - "@typescript-eslint/ban-ts-comment": "off" - }, - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended" - ] - }, - { - "files": [ - "*.cjs" - ], - "parserOptions": { - "ecmaVersion": 2015, - "sourceType": "commonjs" - } - }, - { - "files": [ - "test/browser/*.js" - ], - "env": { - "browser": true - } - } - ] -} diff --git a/.github/workflows/run.yml b/.github/workflows/run.yml index 91b052a..00ba7a8 100644 --- a/.github/workflows/run.yml +++ b/.github/workflows/run.yml @@ -2,6 +2,21 @@ name: 'CI' on: [pull_request, push] jobs: + lint: + runs-on: ubuntu-latest + name: Lint + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + - name: Install dependencies + run: npm ci + - name: Lint + run: npm run lint + + swig: runs-on: ubuntu-latest name: Generate the SWIG wrappers diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..327f229 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,80 @@ +import mocha from 'eslint-plugin-mocha'; +import globals from 'globals'; +import typescriptEslint from '@typescript-eslint/eslint-plugin'; +import tsParser from '@typescript-eslint/parser'; +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/browser/build/*', 'build/*', 'lib/binding/*'], +}, ...compat.extends('eslint:recommended'), { + plugins: { + mocha, + }, + + languageOptions: { + globals: { + ...globals.mocha, + ...globals['shared-node-browser'], + __karma__: true, + process: true, + }, + + ecmaVersion: 2020, + sourceType: 'module', + }, + + rules: { + semi: [2, 'always'], + quotes: ['error', 'single'], + }, +}, ...compat.extends( + 'eslint:recommended', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', +).map(config => ({ + ...config, + files: ['test/*.ts'], +})), { + files: ['test/*.ts'], + + plugins: { + '@typescript-eslint': typescriptEslint, + }, + + languageOptions: { + parser: tsParser, + }, + + rules: { + '@typescript-eslint/ban-ts-comment': 'off', + }, +}, { + files: ['**/*.cjs'], + + languageOptions: { + ecmaVersion: 2015, + sourceType: 'commonjs', + globals: { + ...globals.node + } + }, +}, { + files: ['test/browser/*.js'], + + languageOptions: { + globals: { + ...globals.browser, + }, + }, +}]; diff --git a/package-lock.json b/package-lock.json index a3d4aa9..8d00be4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,8 @@ "xpm": "^0.19.1" }, "devDependencies": { + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "^9.12.0", "@types/chai": "^4.3.14", "@types/mocha": "^10.0.6", "@types/node": "^20.12.7", @@ -26,6 +28,7 @@ "eslint": "^9.12.0", "eslint-plugin-mocha": "^10.5.0", "glob": "^11.0.0", + "globals": "^15.11.0", "karma": "^6.4.3", "karma-chrome-launcher": "^3.2.0", "karma-mocha": "^2.0.1", @@ -2526,6 +2529,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", @@ -3317,15 +3335,12 @@ } }, "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.11.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.11.0.tgz", + "integrity": "sha512-yeyNSjdbyVaWurlwCpcA6XNBrHTMIeDdj0/hnvX/OLJ9ekOXYbLsLinH/MucQyGvNnXhidTdNhTtJaffL2sMfw==", "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 f88435a..73e85db 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "build:wasm": "npm run configure:wasm && npx xpm run build --config wasm", "build:webpack": "cd test/browser && npx webpack --mode=production", "build": "npm run build:native && npm run build:wasm", - "lint": "clang-format -i src/*.cc src/*.h && eslint test", + "lint": "npx eslint", "dev": "cd test/browser && npx webpack serve --mode=production", "gcov": "mkdir -p coverage && cd coverage && gcov -o ../build/Debug/obj.target/proj_js/build -o ../build/Debug/obj.target/proj_js/src ../src/* ../build/*", "lcov": "npx c8 report --reporter=text-lcov > coverage/tests.lcov" @@ -69,6 +69,8 @@ "xpm": "^0.19.1" }, "devDependencies": { + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "^9.12.0", "@types/chai": "^4.3.14", "@types/mocha": "^10.0.6", "@types/node": "^20.12.7", @@ -80,6 +82,7 @@ "eslint": "^9.12.0", "eslint-plugin-mocha": "^10.5.0", "glob": "^11.0.0", + "globals": "^15.11.0", "karma": "^6.4.3", "karma-chrome-launcher": "^3.2.0", "karma-mocha": "^2.0.1",