From 5e01a489e19e8adcd719faba379106a6222128ad Mon Sep 17 00:00:00 2001 From: Mehdy Dara Date: Tue, 5 Mar 2024 14:35:56 +0100 Subject: [PATCH] Fix test --- index.js | 39 ++++++++++++++++++++++++++------------- package.json | 25 ++++++++++++++----------- test/_x.ts | 0 test/test.js | 26 ++++++++++++++------------ tsconfig.json | 3 +++ 5 files changed, 57 insertions(+), 36 deletions(-) create mode 100644 test/_x.ts diff --git a/index.js b/index.js index f0172ff..73ff526 100644 --- a/index.js +++ b/index.js @@ -10,19 +10,6 @@ ruleNamingConventionOverride[1].format = [ ]; module.exports = { - plugins: ['promise'], - extends: ['xo', 'xo-typescript/space', 'plugin:promise/recommended'], - rules: { - 'capitalized-comments': 'off', - 'promise/no-return-wrap': 'off', - 'no-console': 'error', - // Override naming convention rule to allow `snake_case`. - '@typescript-eslint/naming-convention': ruleNamingConventionOverride, - // Override this rule to allow usage of null and undefined. - '@typescript-eslint/ban-types': ruleBanTypeOverride, - // Disable this rule because we need interface and type. - '@typescript-eslint/consistent-type-definitions': 'off', - }, overrides: [ { files: [ @@ -34,5 +21,31 @@ module.exports = { '@typescript-eslint/no-unsafe-assignment': 'off', }, }, + { + files: [ + '*.ts', + ], + plugins: ['promise', 'simple-import-sort'], + extends: ['xo', 'xo-typescript/space', 'plugin:promise/recommended'], + rules: { + 'capitalized-comments': 'off', + 'promise/no-return-wrap': 'off', + 'no-console': 'error', + 'simple-import-sort/imports': 'error', + 'simple-import-sort/exports': 'error', + // Override naming convention rule to allow `snake_case`. + '@typescript-eslint/naming-convention': ruleNamingConventionOverride, + // Override this rule to allow usage of null and undefined. + '@typescript-eslint/ban-types': ruleBanTypeOverride, + // Disable this rule because we need interface and type. + '@typescript-eslint/consistent-type-definitions': 'off', + }, + }, + { + files: ['package.json'], + plugins: ['package-json'], + extends: ['plugin:package-json/recommended'], + parser: 'jsonc-eslint-parser', + }, ], }; diff --git a/package.json b/package.json index 16a6554..97f6723 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "https://www.radiofrance.fr" }, "engines": { - "node": ">=16" + "node": ">=18" }, "scripts": { "lint": "eslint .", @@ -46,22 +46,25 @@ "simple" ], "dependencies": { - "@typescript-eslint/eslint-plugin": "^6.9.0", - "@typescript-eslint/parser": "^6.9.0", - "eslint-config-xo": "^0.43.1", - "eslint-config-xo-typescript": "^1.0.1", + "@typescript-eslint/eslint-plugin": ">=7.0.2", + "@typescript-eslint/parser": ">=7.0.2", + "eslint-config-xo": "^0.44.0", + "eslint-config-xo-typescript": "^3.0.0", + "eslint-plugin-package-json": "^0.10.4", "eslint-plugin-promise": "^6.0.0", - "typescript": ">=5.0.2" + "eslint-plugin-simple-import-sort": "^12.0.0", + "jsonc-eslint-parser": "^2.4.0", + "typescript": ">=5.0.0" }, "devDependencies": { - "ava": "^3.7.1", + "ava": "^6.1.2", "eslint": "^8.52.0" }, "peerDependencies": { - "@typescript-eslint/eslint-plugin": ">=6.0.0", - "@typescript-eslint/parser": ">=6.0.0", - "eslint": ">=8.0.0", - "typescript": ">=5.0.2" + "@typescript-eslint/eslint-plugin": ">=7.0.2", + "@typescript-eslint/parser": ">=7.0.2", + "eslint": ">=8.56.0", + "typescript": ">=5.0.0" }, "eslintConfig": { "extends": "xo", diff --git a/test/_x.ts b/test/_x.ts new file mode 100644 index 0000000..e69de29 diff --git a/test/test.js b/test/test.js index 21aeafe..15368b4 100644 --- a/test/test.js +++ b/test/test.js @@ -1,27 +1,29 @@ -const path = require('path'); const test = require('ava'); -const eslint = require('eslint'); +const {ESLint} = require('eslint'); -const config = '../index.js'; +const config = require('../index.js'); const hasRule = (errors, ruleId) => errors.some(x => x.ruleId === ruleId); -function runEslint(string, config) { - const linter = new eslint.CLIEngine({ +async function runEslint(string, config) { + const eslint = new ESLint({ useEslintrc: false, - configFile: path.join(__dirname, config), + overrideConfig: config, }); - return linter.executeOnText(string, path.join(__dirname, '../_x.ts')).results[0].messages; + const [firstResult] = await eslint.lintText(string, {filePath: 'test/_x.ts'}); + + return firstResult.messages; } -// Cant be fixed due https://github.com/typescript-eslint/typescript-eslint/issues/885 -test.failing('main', t => { - const errors = runEslint('const foo: number = 5;', config); +test('should throw error no-inferrable-types', async t => { + const errors = await runEslint('const foo: number = 5;\n', config); t.true(hasRule(errors, '@typescript-eslint/no-inferrable-types'), JSON.stringify(errors)); + t.is(errors.length, 1); }); -test.failing('main error no-console', t => { - const errors = runEslint('\'use strict\';\nconst x = true;\n\nif (x) {\n console.log();\n}\n', config); +test('should throw error no-console', async t => { + const errors = await runEslint('\'use strict\';\nconst x = true;\n\nif (x) {\n console.log();\n}\n', config); t.true(hasRule(errors, 'no-console'), JSON.stringify(errors)); + t.is(errors.length, 1); }); diff --git a/tsconfig.json b/tsconfig.json index 1bbe77a..495c881 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,7 @@ { + "compilerOptions": { + "strict": true, + }, "include": [ "test" ]