Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
Tweak
Browse files Browse the repository at this point in the history
* Add eslint-plugin-import
* Reactivate rule promise/no-return-wrap
* Use override for TS files
* Remove override for test files in TS
* Require node 18
* Add CI with Github
* Fix test
* Bump deps
  • Loading branch information
zckrs committed Mar 6, 2024
1 parent 74973b6 commit 956a97c
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 47 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 20
- 18
- 16
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

41 changes: 24 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,35 @@ 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: [
'test/**/*.ts',
'*.ts',
],
plugins: ['promise', 'import'],
extends: ['xo', 'xo-typescript/space', 'plugin:promise/recommended'],
rules: {
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'capitalized-comments': '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',
'import/extensions': [
'error',
'ignorePackages',
],
'import/no-duplicates': 'error',
'import/order': [
'error',
{
alphabetize: {
order: 'asc',
},
},
],
},
},
],
Expand Down
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"author": {
"name": "Radio France",
"email": "opensource@radiofrance.com",
"url": "www.radiofrance.fr"
"url": "https://www.radiofrance.fr"
},
"engines": {
"node": ">=8"
"node": ">=18"
},
"scripts": {
"lint": "eslint .",
Expand Down Expand Up @@ -46,22 +46,23 @@
"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-import": "^2.29.1",
"eslint-plugin-promise": "^6.0.0",
"typescript": ">=5.0.2"
"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",
Expand Down
Empty file added test/_x.ts
Empty file.
26 changes: 14 additions & 12 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -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);
});
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"compilerOptions": {
"strict": true,
},
"include": [
"test"
]
Expand Down

0 comments on commit 956a97c

Please sign in to comment.