Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: tighter linting #530

Merged
merged 5 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
173 changes: 173 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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