Skip to content

Commit

Permalink
chore: tighter linting (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed May 16, 2019
1 parent 035b066 commit 508bb41
Show file tree
Hide file tree
Showing 22 changed files with 333 additions and 108 deletions.
173 changes: 173 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,173 @@
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: {
//
// eslint base
//

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

//
// our plugin :D
//

'@typescript-eslint/indent': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/no-parameter-properties': 'off',

//
// 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',

//
// 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',
],
},
],
},
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.

11 changes: 2 additions & 9 deletions package.json
Expand Up @@ -47,31 +47,24 @@
"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",
"cz-conventional-changelog": "2.1.0",
"eslint": "^5.12.1",
"eslint-plugin-eslint-comments": "^3.1.1",
"eslint-plugin-eslint-plugin": "^2.0.1",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jest": "^22.2.2",
"glob": "7.1.2",
"husky": "^1.3.1",
"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",
"rimraf": "^2.6.3",
"ts-jest": "^24.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin-tslint/package.json
Expand Up @@ -32,7 +32,8 @@
},
"peerDependencies": {
"eslint": "^5.0.0",
"tslint": "^5.0.0"
"tslint": "^5.0.0",
"typescript": "*"
},
"devDependencies": {
"@types/json-schema": "^7.0.3",
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-plugin/package.json
Expand Up @@ -44,7 +44,9 @@
"tsutils": "^3.7.0"
},
"devDependencies": {
"eslint-docs": "^0.2.6"
"@typescript-eslint/parser": "1.9.0",
"eslint-docs": "^0.2.6",
"typescript": "*"
},
"peerDependencies": {
"@typescript-eslint/parser": "1.9.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-magic-numbers.ts
Expand Up @@ -8,8 +8,8 @@ import {
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import baseRule from 'eslint/lib/rules/no-magic-numbers';
import { JSONSchema4 } from 'json-schema'; // eslint-disable-line import/no-extraneous-dependencies
import * as util from '../util';
import { JSONSchema4 } from 'json-schema';

type Options = util.InferOptionsTypeFromRule<typeof baseRule>;
type MessageIds = util.InferMessageIdsTypeFromRule<typeof baseRule>;
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/prefer-regexp-exec.ts
@@ -1,6 +1,6 @@
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { createRule, getParserServices, getTypeName } from '../util';
import { TSESTree } from '@typescript-eslint/experimental-utils';
import { getStaticValue } from 'eslint-utils';
import { createRule, getParserServices, getTypeName } from '../util';

export default createRule({
name: 'prefer-regexp-exec',
Expand Down
2 changes: 0 additions & 2 deletions packages/eslint-plugin/tools/generate-configs.ts
@@ -1,5 +1,3 @@
/* eslint-disable no-console */

import { TSESLint } from '@typescript-eslint/experimental-utils';
import fs from 'fs';
import path from 'path';
Expand Down
5 changes: 4 additions & 1 deletion packages/experimental-utils/package.json
Expand Up @@ -32,11 +32,14 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@types/json-schema": "^7.0.3",
"@typescript-eslint/typescript-estree": "1.9.0",
"eslint-scope": "^4.0.0"
},
"peerDependencies": {
"eslint": "*",
"eslint": "*"
},
"devDependencies": {
"typescript": "*"
}
}
2 changes: 1 addition & 1 deletion packages/experimental-utils/src/ts-eslint/CLIEngine.ts
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-namespace, no-redeclare */
/* eslint-disable @typescript-eslint/no-namespace */

import { CLIEngine as ESLintCLIEngine } from 'eslint';
import { Linter } from './Linter';
Expand Down
2 changes: 1 addition & 1 deletion packages/experimental-utils/src/ts-eslint/Linter.ts
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-namespace, no-redeclare */
/* eslint-disable @typescript-eslint/no-namespace */

import { TSESTree, ParserServices } from '@typescript-eslint/typescript-estree';
import { Linter as ESLintLinter } from 'eslint';
Expand Down
2 changes: 1 addition & 1 deletion packages/experimental-utils/src/ts-eslint/Rule.ts
@@ -1,5 +1,5 @@
import { ParserServices, TSESTree } from '@typescript-eslint/typescript-estree';
import { JSONSchema4 } from 'json-schema';
import { JSONSchema4 } from 'json-schema'; // eslint-disable-line import/no-extraneous-dependencies
import { AST } from './AST';
import { Linter } from './Linter';
import { Scope } from './Scope';
Expand Down
2 changes: 1 addition & 1 deletion packages/experimental-utils/src/ts-eslint/SourceCode.ts
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-namespace, no-redeclare */
/* eslint-disable @typescript-eslint/no-namespace */

import { ParserServices, TSESTree } from '@typescript-eslint/typescript-estree';
import { SourceCode as ESLintSourceCode } from 'eslint';
Expand Down
4 changes: 3 additions & 1 deletion packages/parser/package.json
Expand Up @@ -43,6 +43,8 @@
"eslint-visitor-keys": "^1.0.0"
},
"devDependencies": {
"@typescript-eslint/shared-fixtures": "1.9.0"
"@types/glob": "^7.1.1",
"@typescript-eslint/shared-fixtures": "1.9.0",
"glob": "^7.1.4"
}
}
1 change: 1 addition & 0 deletions packages/parser/typings/eslint.d.ts
@@ -1,5 +1,6 @@
declare module 'eslint/lib/util/traverser' {
import { TSESTree } from '@typescript-eslint/experimental-utils';

const traverser: {
traverse(
node: TSESTree.Node,
Expand Down

0 comments on commit 508bb41

Please sign in to comment.