diff --git a/.eslintignore b/.eslintignore index de4d1f007..18f2b36db 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ +coverage dist node_modules diff --git a/.eslintrc.js b/.eslintrc.js index a64a864fa..960fc6e08 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,11 +2,13 @@ module.exports = { root: true, parser: '@typescript-eslint/parser', parserOptions: { - tsconfigRootDir: __dirname, // this is the reason this is a .js file - project: ['./tsconfig.json', './test/tsconfig.json'], + tsconfigRootDir: __dirname, + project: [ './tsconfig.json', './test/tsconfig.json' ], }, - globals: { + globals: { + // eslint-disable-next-line @typescript-eslint/naming-convention AsyncIterable: 'readonly', + // eslint-disable-next-line @typescript-eslint/naming-convention NodeJS: 'readonly', }, plugins: [ @@ -23,81 +25,105 @@ module.exports = { ], settings: { 'import/resolver': { - 'typescript': { - 'alwaysTryTypes': true // always try to resolve types under `@types` directory even it doesn't contain any source code, like `@types/rdf-js` + typescript: { + // Always try to resolve types under `@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` - 'comma-dangle': ['error', 'always-multiline'], - 'dot-location': ['error', 'property'], - 'generator-star-spacing': ['error', 'after'], - 'lines-around-comment': 'off', // conflicts with padded-blocks - '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 + // 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' ], + // Conflicts with padded-blocks + 'lines-around-comment': 'off', + 'lines-between-class-members': [ 'error', 'always', { exceptAfterSingleLine: true }], + 'max-len': [ 'error', { code: 120, ignoreUrls: true }], + // 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 - 'yield-star-spacing': ['error', 'after'], + // Can get ugly with large single statements + 'unicorn/prefer-ternary': 'off', + 'yield-star-spacing': [ 'error', 'after' ], // Naming conventions '@typescript-eslint/naming-convention': [ 'error', { selector: 'default', - format: ['camelCase'], + format: [ 'camelCase' ], leadingUnderscore: 'forbid', trailingUnderscore: 'forbid', }, { selector: 'variable', - format: ['camelCase', 'UPPER_CASE'], + format: [ 'camelCase', 'UPPER_CASE' ], leadingUnderscore: 'forbid', trailingUnderscore: 'forbid', }, { selector: 'typeLike', - format: ['PascalCase'], + format: [ 'PascalCase' ], }, { 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 - 'import/order': ['error', { + '@typescript-eslint/consistent-type-imports': [ 'error', { prefer: 'type-imports' }], + // 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', + }, + ], }; diff --git a/bin/server.js b/bin/server.js index afaf57966..dcfa789f7 100755 --- a/bin/server.js +++ b/bin/server.js @@ -1,3 +1,3 @@ #!/usr/bin/env node -const { runCli } = require(".."); +const { runCli } = require('..'); runCli(); diff --git a/jest.config.js b/jest.config.js index 49758e919..de130e245 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,32 +1,33 @@ module.exports = { - "globals": { - "ts-jest": { - "tsconfig": "tsconfig.json" - } + globals: { + 'ts-jest': { + tsconfig: 'tsconfig.json', + }, }, - "transform": { - "^.+\\.ts$": "ts-jest" + transform: { + '^.+\\.ts$': 'ts-jest', }, - "testRegex": "/test/(unit|integration)/.*\\.test\\.ts$", - "moduleFileExtensions": [ - "ts", - "js" + testRegex: '/test/(unit|integration)/.*\\.test\\.ts$', + moduleFileExtensions: [ + 'ts', + 'js', ], - "testEnvironment": "node", - "setupFilesAfterEnv": ["jest-rdf", "/test/util/SetupTests.ts"], - "collectCoverage": true, - "coveragePathIgnorePatterns": [ - "/dist/", - "/node_modules/", - "/test/" + testEnvironment: 'node', + setupFilesAfterEnv: [ 'jest-rdf', '/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, }; diff --git a/package.json b/package.json index 016dfa8a6..fe7e530bc 100644 --- a/package.json +++ b/package.json @@ -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",