Skip to content

Commit

Permalink
upgrade to eslint 9 and lint in CI (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev authored Jan 30, 2025
1 parent d7817f7 commit 091b074
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 101 deletions.
77 changes: 0 additions & 77 deletions .eslintrc.json

This file was deleted.

86 changes: 86 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import preferArrow from 'eslint-plugin-prefer-arrow';
import globals from 'globals';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import mocha from 'eslint-plugin-mocha';
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 [
...compat.extends('eslint:recommended'),
{
plugins: {
'prefer-arrow': preferArrow,
},

languageOptions: {
globals: {
...globals.mocha,
...globals.node,
BigInt64Array: 'readonly',
BigUint64Array: 'readonly',
},

ecmaVersion: 2019,
sourceType: 'commonjs',
},

rules: {
'max-len': [1, {
code: 120,
tabWidth: 2,
ignoreUrls: true,
}],

semi: [2, 'always'],

quotes: ['error', 'single', {
avoidEscape: true,
allowTemplateLiterals: true,
}],

'@typescript-eslint/no-explicit-any': 'off',
},
},
...compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
).map(config => ({
...config,
files: ['test/*.ts', 'lib/*.d.ts'],
})),
{
files: ['test/*.ts', 'lib/*.d.ts'],

plugins: {
'@typescript-eslint': typescriptEslint,
mocha,
'prefer-arrow': preferArrow,
},

rules: {
'mocha/no-exclusive-tests': 'error',
'mocha/no-identical-title': 'error',
'mocha/no-nested-tests': 'error',
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['**/*.mjs'],

languageOptions: {
ecmaVersion: 5,
sourceType: 'module',
},
},
];
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports.PyObject.prototype[Symbol.iterator] = function () {
done: false,
value: el
};
} catch (e) {
} catch {
return {
done: true,
value: null
Expand Down
38 changes: 21 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
"bench": "node bench/bench.js"
},
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.19.0",
"@types/chai": "^4.3.11",
"@types/chai-spies": "^1.0.6",
"@types/mocha": "^10.0.6",
Expand All @@ -78,9 +80,9 @@
"chai-spies": "^1.1.0",
"documentation": "^14.0.0",
"eslint": "^9.8.0",
"eslint-plugin-array-func": "^5.0.1",
"eslint-plugin-mocha": "^10.4.1",
"eslint-plugin-prefer-arrow": "^1.2.3",
"globals": "^15.14.0",
"mocha": "github:mmomtchev/mocha#mmom",
"node-gyp": "^11.0.0",
"ts-node": "^10.9.2",
Expand Down
1 change: 0 additions & 1 deletion test/_init.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
process.env['PYTHONPATH'] = __dirname;

import { assert } from 'chai';
import { version, pymport } from 'pymport';

console.log(`pymport: ` +
Expand Down
2 changes: 1 addition & 1 deletion test/pymport.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-expressions */
import { pymport, PyObject, PythonError, version } from 'pymport';
import chai from 'chai';
import spies from 'chai-spies';
Expand All @@ -21,7 +22,6 @@ describe('pymport', () => {
assert.isBoolean(version.pythonLibrary.builtin);
if (version.pythonLibrary.builtin) {
assert.isString(version.pythonHome);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const builtin_version = process.env.BUILTIN_PYTHON_VERSION!.split('.').map((v) => +v);
assert.strictEqual(version.pythonLibrary.major, builtin_version[0]);
assert.strictEqual(version.pythonLibrary.minor, builtin_version[1]);
Expand Down
2 changes: 0 additions & 2 deletions test/worker-stress-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { Worker } = require('worker_threads');
const path = require('path');
const Queue = require('async-await-queue');
Expand All @@ -22,7 +21,6 @@ function spawnWorker(script) {
async function main() {
let i = 0;
console.log('start');
// eslint-disable-next-line no-constant-condition
while (true) {
const me = Symbol();
queue.wait(me)
Expand Down
1 change: 0 additions & 1 deletion test/worker_thread.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { pyval } = require('pymport');
const { parentPort, workerData } = require('worker_threads');

Expand Down

0 comments on commit 091b074

Please sign in to comment.