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 dist
node_modules node_modules

View File

@ -2,11 +2,13 @@ module.exports = {
root: true, root: true,
parser: '@typescript-eslint/parser', parser: '@typescript-eslint/parser',
parserOptions: { parserOptions: {
tsconfigRootDir: __dirname, // this is the reason this is a .js file tsconfigRootDir: __dirname,
project: [ './tsconfig.json', './test/tsconfig.json' ], project: [ './tsconfig.json', './test/tsconfig.json' ],
}, },
globals: { globals: {
// eslint-disable-next-line @typescript-eslint/naming-convention
AsyncIterable: 'readonly', AsyncIterable: 'readonly',
// eslint-disable-next-line @typescript-eslint/naming-convention
NodeJS: 'readonly', NodeJS: 'readonly',
}, },
plugins: [ plugins: [
@ -23,41 +25,56 @@ module.exports = {
], ],
settings: { settings: {
'import/resolver': { 'import/resolver': {
'typescript': { typescript: {
'alwaysTryTypes': true // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/rdf-js` // Always try to resolve types under `<root>@types` directory
// even it doesn't contain any source code, like `@types/rdf-js`
alwaysTryTypes: true,
},
}, },
}
}, },
rules: { 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/lines-between-class-members': [ 'error', { exceptAfterSingleLine: true }],
'@typescript-eslint/no-empty-interface': 'off', '@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-invalid-void-type': 'off', // breaks with default void in Asynchandler 2nd generic // Breaks with default void in AsyncHandler 2nd generic
'@typescript-eslint/no-unnecessary-condition': 'off', // problems with optional parameters '@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/space-before-function-paren': [ 'error', 'never' ],
'@typescript-eslint/unbound-method': 'off', '@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/unified-signatures': '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' ], 'comma-dangle': [ 'error', 'always-multiline' ],
'dot-location': [ 'error', 'property' ], 'dot-location': [ 'error', 'property' ],
'generator-star-spacing': [ 'error', 'after' ], '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 }], 'lines-between-class-members': [ 'error', 'always', { exceptAfterSingleLine: true }],
'max-len': [ 'error', { code: 120, ignoreUrls: true }], 'max-len': [ 'error', { code: 120, ignoreUrls: true }],
'new-cap': 'off', // used for RDF constants // Used for RDF constants
'no-param-reassign': 'off', // necessary in constructor overloading 'new-cap': 'off',
'no-underscore-dangle': 'off', // conflicts with external libraries // Necessary in constructor overloading
'no-unused-vars': 'off', // already checked by @typescript-eslint/no-unused-vars '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', 'padding-line-between-statements': 'off',
'prefer-named-capture-group': 'off', 'prefer-named-capture-group': 'off',
// Already generated by TypeScript
strict: 'off',
'tsdoc/syntax': 'error', 'tsdoc/syntax': 'error',
'unicorn/catch-error-name': 'off', 'unicorn/catch-error-name': 'off',
'unicorn/import-index': 'off', 'unicorn/import-index': 'off',
'unicorn/import-style': '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/no-object-as-default-parameter': 'off',
'unicorn/numeric-separators-style': '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' ], 'yield-star-spacing': [ 'error', 'after' ],
// Naming conventions // Naming conventions
@ -83,21 +100,30 @@ module.exports = {
selector: [ 'typeParameter' ], selector: [ 'typeParameter' ],
format: [ 'PascalCase' ], format: [ 'PascalCase' ],
prefix: [ 'T' ], prefix: [ 'T' ],
} },
], ],
// Import // Import
'@typescript-eslint/consistent-type-imports': [ 'error', { prefer: 'type-imports' }], '@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', { 'import/order': [ 'error', {
alphabetize: { alphabetize: {
order: 'asc', order: 'asc',
caseInsensitive: true, caseInsensitive: true,
} },
}], }],
'import/no-duplicates': 'error', 'import/no-duplicates': 'error',
'import/no-extraneous-dependencies': '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', 'unused-imports/no-unused-imports-ts': 'error',
}, },
overrides: [
{
files: '*.js',
parser: 'espree',
},
],
}; };

View File

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

View File

@ -1,32 +1,33 @@
module.exports = { module.exports = {
"globals": { globals: {
"ts-jest": { 'ts-jest': {
"tsconfig": "tsconfig.json" tsconfig: 'tsconfig.json',
}
}, },
"transform": {
"^.+\\.ts$": "ts-jest"
}, },
"testRegex": "/test/(unit|integration)/.*\\.test\\.ts$", transform: {
"moduleFileExtensions": [ '^.+\\.ts$': 'ts-jest',
"ts", },
"js" testRegex: '/test/(unit|integration)/.*\\.test\\.ts$',
moduleFileExtensions: [
'ts',
'js',
], ],
"testEnvironment": "node", testEnvironment: 'node',
"setupFilesAfterEnv": ["jest-rdf", "<rootDir>/test/util/SetupTests.ts"], setupFilesAfterEnv: [ 'jest-rdf', '<rootDir>/test/util/SetupTests.ts' ],
"collectCoverage": true, collectCoverage: true,
"coveragePathIgnorePatterns": [ coveragePathIgnorePatterns: [
"/dist/", '/dist/',
"/node_modules/", '/node_modules/',
"/test/" '/test/',
], ],
"coverageThreshold": { coverageThreshold: {
"./src": { './src': {
"branches": 100, branches: 100,
"functions": 100, functions: 100,
"lines": 100, lines: 100,
"statements": 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:start": "./test/docker/docker-start.sh",
"docker:stop": "./test/docker/docker-stop.sh", "docker:stop": "./test/docker/docker-stop.sh",
"jest": "jest", "jest": "jest",
"lint": "eslint . --ext .ts --cache", "lint": "eslint . --cache",
"prepare": "npm run build", "prepare": "npm run build",
"start": "node ./bin/server.js -p 3000", "start": "node ./bin/server.js -p 3000",
"test": "npm run test:tsc && npm run jest", "test": "npm run test:tsc && npm run jest",