Skip to content

Commit

Permalink
chore: tighter linting (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Jul 25, 2019
1 parent 211b1b5 commit 4496288
Show file tree
Hide file tree
Showing 96 changed files with 3,454 additions and 1,826 deletions.
181 changes: 181 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,181 @@
module.exports = {
root: true,
plugins: [
'eslint-plugin',
'@typescript-eslint',
'jest',
'import',
'eslint-comments',
],
env: {
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
//
// our plugin :D
//

'@typescript-eslint/ban-ts-ignore': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/indent': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-regexp-exec': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',

//
// eslint base
//

'comma-dangle': ['error', 'always-multiline'],
curly: ['error', 'all'],
'no-mixed-operators': 'error',
'no-console': 'error',
'no-process-exit': 'error',

//
// eslint-plugin-eslint-comment
//

// require a eslint-enable comment for every eslint-disable comment
'eslint-comments/disable-enable-pair': [
'error',
{
allowWholeFile: true,
},
],
// disallow a eslint-enable comment for multiple eslint-disable comments
'eslint-comments/no-aggregating-enable': 'error',
// disallow duplicate eslint-disable comments
'eslint-comments/no-duplicate-disable': 'error',
// disallow eslint-disable comments without rule names
'eslint-comments/no-unlimited-disable': 'error',
// disallow unused eslint-disable comments
'eslint-comments/no-unused-disable': 'error',
// disallow unused eslint-enable comments
'eslint-comments/no-unused-enable': 'error',
// disallow ESLint directive-comments
'eslint-comments/no-use': [
'error',
{
allow: [
'eslint-disable',
'eslint-disable-line',
'eslint-disable-next-line',
'eslint-enable',
],
},
],

//
// eslint-plugin-import
//

// disallow non-import statements appearing before import statements
'import/first': 'error',
// Require a newline after the last import/require in a group
'import/newline-after-import': 'error',
// Forbid import of modules using absolute paths
'import/no-absolute-path': 'error',
// disallow AMD require/define
'import/no-amd': 'error',
// forbid default exports
'import/no-default-export': 'error',
// Forbid the use of extraneous packages
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: true,
peerDependencies: true,
optionalDependencies: false,
},
],
// Forbid mutable exports
'import/no-mutable-exports': 'error',
// Prevent importing the default as if it were named
'import/no-named-default': 'error',
// Prohibit named exports // we want everything to be a named export
'import/no-named-export': 'off',
// Forbid a module from importing itself
'import/no-self-import': 'error',
// Require modules with a single export to use a default export // we want everything to be named
'import/prefer-default-export': 'off',
},
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: false,
},
project: './tsconfig.base.json',
},
overrides: [
{
files: [
'packages/eslint-plugin-tslint/tests/**/*.ts',
'packages/eslint-plugin/tests/**/*.test.ts',
'packages/parser/tests/**/*.ts',
'packages/typescript-estree/tests/**/*.ts',
],
env: {
'jest/globals': true,
},
rules: {
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-alias-methods': 'error',
'jest/no-identical-title': 'error',
'jest/no-jasmine-globals': 'error',
'jest/no-jest-import': 'error',
'jest/no-test-prefixes': 'error',
'jest/no-test-callback': 'error',
'jest/no-test-return-statement': 'error',
'jest/prefer-to-have-length': 'warn',
'jest/prefer-spy-on': 'error',
'jest/valid-expect': 'error',
},
},
{
files: [
'packages/eslint-plugin/tests/**/*.test.ts',
'packages/eslint-plugin-tslint/tests/**/*.spec.ts',
],
rules: {
'eslint-plugin/no-identical-tests': 'error',
},
},
{
files: [
'packages/eslint-plugin/src/rules/**/*.ts',
'packages/eslint-plugin/src/configs/**/*.ts',
'packages/eslint-plugin-tslint/src/rules/**/*.ts',
],
rules: {
// specifically for rules - default exports makes the tooling easier
'import/no-default-export': 'off',
},
},
{
files: ['**/tools/**/*.ts', '**/tests/**/*.ts'],
rules: {
// allow console logs in tools and tests
'no-console': 'off',
},
},
],
};
73 changes: 0 additions & 73 deletions .eslintrc.json

This file was deleted.

43 changes: 18 additions & 25 deletions package.json
Expand Up @@ -50,36 +50,29 @@
"node": ">=6.14.0"
},
"devDependencies": {
"@babel/code-frame": "7.0.0",
"@babel/parser": "7.3.2",
"@commitlint/cli": "^7.1.2",
"@commitlint/config-conventional": "^7.1.2",
"@commitlint/travis-cli": "^7.1.2",
"@types/babel-code-frame": "^6.20.1",
"@types/glob": "^7.1.1",
"@types/jest": "^24.0.6",
"@types/lodash.isplainobject": "^4.0.4",
"@types/lodash.unescape": "^4.0.4",
"@types/node": "^10.12.2",
"@types/semver": "^5.5.0",
"all-contributors-cli": "^6.0.0",
"babel-code-frame": "^6.26.0",
"@commitlint/cli": "^8.1.0",
"@commitlint/config-conventional": "^8.1.0",
"@commitlint/travis-cli": "^8.1.0",
"@types/jest": "^24.0.15",
"@types/node": "^12.6.8",
"all-contributors-cli": "^6.8.0",
"cz-conventional-changelog": "2.1.0",
"eslint": "^6.0.0",
"eslint-plugin-eslint-plugin": "^2.0.1",
"eslint-plugin-jest": "^22.2.2",
"glob": "7.1.2",
"husky": "^1.3.1",
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-eslint-plugin": "^2.1.0",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-jest": "^22.10.0",
"glob": "^7.1.4",
"husky": "^3.0.0",
"isomorphic-fetch": "^2.2.1",
"jest": "24.3.0",
"lerna": "^3.10.5",
"lint-staged": "8.1.0",
"lodash.isplainobject": "4.0.6",
"prettier": "^1.17.0",
"jest": "^24.8.0",
"lerna": "^3.15.0",
"lint-staged": "^9.2.0",
"prettier": "^1.18.2",
"rimraf": "^2.6.3",
"ts-jest": "^24.0.0",
"ts-node": "^8.0.1",
"tslint": "^5.11.0",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"typescript": ">=3.2.1 <3.6.0"
}
}
3 changes: 2 additions & 1 deletion packages/eslint-plugin-tslint/package.json
Expand Up @@ -36,7 +36,8 @@
},
"peerDependencies": {
"eslint": "^5.0.0 || ^6.0.0",
"tslint": "^5.0.0"
"tslint": "^5.0.0",
"typescript": "*"
},
"devDependencies": {
"@types/lodash.memoize": "^4.1.4",
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin-tslint/src/custom-linter.ts
@@ -1,6 +1,8 @@
import { ILinterOptions, Linter, LintResult } from 'tslint';
import { Program } from 'typescript';

// We need to access the program, but Linter has private program already
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const TSLintLinter = Linter as any;

export class CustomLinter extends TSLintLinter {
Expand Down
11 changes: 6 additions & 5 deletions packages/eslint-plugin-tslint/src/rules/config.ts
Expand Up @@ -18,10 +18,10 @@ export type RawRulesConfig = Record<
| null
| undefined
| boolean
| any[]
| unknown[]
| {
severity?: RuleSeverity | 'warn' | 'none' | 'default';
options?: any;
options?: unknown;
}
>;

Expand All @@ -31,7 +31,7 @@ export type Options = [
rules?: RawRulesConfig;
rulesDirectory?: string[];
lintFile?: string;
}
},
];

/**
Expand Down Expand Up @@ -63,7 +63,8 @@ export default createRule<Options, MessageIds>({
docs: {
description:
'Wraps a TSLint configuration and lints the whole source using TSLint',
category: 'TSLint' as any,
// one off special category for this plugin
category: 'TSLint' as any, // eslint-disable-line @typescript-eslint/no-explicit-any
recommended: false,
},
type: 'problem',
Expand Down Expand Up @@ -95,7 +96,7 @@ export default createRule<Options, MessageIds>({
},
],
},
defaultOptions: [] as any,
defaultOptions: [{}],
create(context) {
const fileName = context.getFilename();
const sourceCode = context.getSourceCode().text;
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/generic-type-naming.md
Expand Up @@ -15,7 +15,7 @@ Examples of **correct** code with a configuration of `'^T[A-Z][a-zA-Z]+$'`:

```typescript
type ReadOnly<TType extends object> = {
readonly [TKey in keyof TType]: TType[TKey]
readonly [TKey in keyof TType]: TType[TKey];
};

interface SimpleMap<TValue> {
Expand Down

0 comments on commit 4496288

Please sign in to comment.