From 87add6581bc2fc90a70899a310b6e52f368c7d1b 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 | 6 ++++++ package.json | 24 +++++++++++++----------- test/_x.ts | 0 test/test.js | 26 ++++++++++++++------------ tsconfig.json | 3 +++ 5 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 test/_x.ts diff --git a/index.js b/index.js index f0172ff..41cc06e 100644 --- a/index.js +++ b/index.js @@ -34,5 +34,11 @@ module.exports = { '@typescript-eslint/no-unsafe-assignment': 'off', }, }, + { + extends: ['plugin:package-json/recommended'], + files: ['package.json'], + parser: 'jsonc-eslint-parser', + plugins: ['package-json'], + }, ], }; diff --git a/package.json b/package.json index 16a6554..ceb909c 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,24 @@ "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" + "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" ]