chore: Extend linting to .js files.

This commit is contained in:
Ruben Verborgh 2020-12-13 15:19:44 +00:00
parent 14023e4c0c
commit d9f18f813e
5 changed files with 87 additions and 59 deletions

View File

@ -1,2 +1,3 @@
coverage
dist
node_modules

View File

@ -2,11 +2,13 @@ module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname, // this is the reason this is a .js file
tsconfigRootDir: __dirname,
project: [ './tsconfig.json', './test/tsconfig.json' ],
},
globals: {
// eslint-disable-next-line @typescript-eslint/naming-convention
AsyncIterable: 'readonly',
// eslint-disable-next-line @typescript-eslint/naming-convention
NodeJS: 'readonly',
},
plugins: [
@ -23,41 +25,56 @@ module.exports = {
],
settings: {
'import/resolver': {
'typescript': {
'alwaysTryTypes': true // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/rdf-js`
typescript: {
// Always try to resolve types under `<root>@types` directory
// even it doesn't contain any source code, like `@types/rdf-js`
alwaysTryTypes: true,
},
},
}
},
rules: {
'@typescript-eslint/consistent-type-definitions': 'off', // there are valid typing reasons to have one or the other
// There are valid typing reasons to have one or the other
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/lines-between-class-members': [ 'error', { exceptAfterSingleLine: true }],
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-invalid-void-type': 'off', // breaks with default void in Asynchandler 2nd generic
'@typescript-eslint/no-unnecessary-condition': 'off', // problems with optional parameters
// Breaks with default void in AsyncHandler 2nd generic
'@typescript-eslint/no-invalid-void-type': 'off',
// Problems with optional parameters
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/space-before-function-paren': [ 'error', 'never' ],
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/unified-signatures': 'off',
'class-methods-use-this': 'off', // conflicts with functions from interfaces that sometimes don't require `this`
// Conflicts with functions from interfaces that sometimes don't require `this`
'class-methods-use-this': 'off',
'comma-dangle': [ 'error', 'always-multiline' ],
'dot-location': [ 'error', 'property' ],
'generator-star-spacing': [ 'error', 'after' ],
'lines-around-comment': 'off', // conflicts with padded-blocks
// Conflicts with padded-blocks
'lines-around-comment': 'off',
'lines-between-class-members': [ 'error', 'always', { exceptAfterSingleLine: true }],
'max-len': [ 'error', { code: 120, ignoreUrls: true }],
'new-cap': 'off', // used for RDF constants
'no-param-reassign': 'off', // necessary in constructor overloading
'no-underscore-dangle': 'off', // conflicts with external libraries
'no-unused-vars': 'off', // already checked by @typescript-eslint/no-unused-vars
// Used for RDF constants
'new-cap': 'off',
// Necessary in constructor overloading
'no-param-reassign': 'off',
// Conflicts with external libraries
'no-underscore-dangle': 'off',
// Already checked by @typescript-eslint/no-unused-vars
'no-unused-vars': 'off',
'padding-line-between-statements': 'off',
'prefer-named-capture-group': 'off',
// Already generated by TypeScript
strict: 'off',
'tsdoc/syntax': 'error',
'unicorn/catch-error-name': 'off',
'unicorn/import-index': 'off',
'unicorn/import-style': 'off',
'unicorn/no-fn-reference-in-iterator': 'off', // this prevents some functional programming paradigms
// This prevents some functional programming paradigms
'unicorn/no-fn-reference-in-iterator': 'off',
'unicorn/no-object-as-default-parameter': 'off',
'unicorn/numeric-separators-style': 'off',
'unicorn/prefer-ternary': 'off', // can get ugly with large single statements
// Can get ugly with large single statements
'unicorn/prefer-ternary': 'off',
'yield-star-spacing': [ 'error', 'after' ],
// Naming conventions
@ -83,21 +100,30 @@ module.exports = {
selector: [ 'typeParameter' ],
format: [ 'PascalCase' ],
prefix: [ 'T' ],
}
},
],
// Import
'@typescript-eslint/consistent-type-imports': [ 'error', { prefer: 'type-imports' }],
'sort-imports': 'off', // Disabled in favor of eslint-plugin-import
// Disabled in favor of eslint-plugin-import
'sort-imports': 'off',
'import/order': [ 'error', {
alphabetize: {
order: 'asc',
caseInsensitive: true,
}
},
}],
'import/no-duplicates': 'error',
'import/no-extraneous-dependencies': 'error',
'no-duplicate-imports': 'off', // doesn't work with type imports
// Doesn't work with type imports
'no-duplicate-imports': 'off',
'unused-imports/no-unused-imports-ts': 'error',
},
overrides: [
{
files: '*.js',
parser: 'espree',
},
],
};

View File

@ -1,3 +1,3 @@
#!/usr/bin/env node
const { runCli } = require("..");
const { runCli } = require('..');
runCli();

View File

@ -1,32 +1,33 @@
module.exports = {
"globals": {
"ts-jest": {
"tsconfig": "tsconfig.json"
}
globals: {
'ts-jest': {
tsconfig: 'tsconfig.json',
},
"transform": {
"^.+\\.ts$": "ts-jest"
},
"testRegex": "/test/(unit|integration)/.*\\.test\\.ts$",
"moduleFileExtensions": [
"ts",
"js"
transform: {
'^.+\\.ts$': 'ts-jest',
},
testRegex: '/test/(unit|integration)/.*\\.test\\.ts$',
moduleFileExtensions: [
'ts',
'js',
],
"testEnvironment": "node",
"setupFilesAfterEnv": ["jest-rdf", "<rootDir>/test/util/SetupTests.ts"],
"collectCoverage": true,
"coveragePathIgnorePatterns": [
"/dist/",
"/node_modules/",
"/test/"
testEnvironment: 'node',
setupFilesAfterEnv: [ 'jest-rdf', '<rootDir>/test/util/SetupTests.ts' ],
collectCoverage: true,
coveragePathIgnorePatterns: [
'/dist/',
'/node_modules/',
'/test/',
],
"coverageThreshold": {
"./src": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
coverageThreshold: {
'./src': {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
"testTimeout": 10000, // Slower machines had problems calling the WebSocket integration callbacks on time
},
// Slower machines had problems calling the WebSocket integration callbacks on time
testTimeout: 10000,
};

View File

@ -47,7 +47,7 @@
"docker:start": "./test/docker/docker-start.sh",
"docker:stop": "./test/docker/docker-stop.sh",
"jest": "jest",
"lint": "eslint . --ext .ts --cache",
"lint": "eslint . --cache",
"prepare": "npm run build",
"start": "node ./bin/server.js -p 3000",
"test": "npm run test:tsc && npm run jest",