Skip to content

Commit

Permalink
chore(lint): migrate tslint -> eslint migration & prettier (stryker-m…
Browse files Browse the repository at this point in the history
…utator#1731)

* Migrate tslint config to eslint
* Configure eslint with typescript parser
* Configure vscode to fix on save
* Document eslint in CONTRIBUTING.md
  • Loading branch information
Bartosz Leoniak authored and nicojs committed Oct 17, 2019
1 parent 3273bc6 commit 9c693ee
Show file tree
Hide file tree
Showing 357 changed files with 2,943 additions and 2,799 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 2 space indentation
[{*.ts,*.js,*.json}]
[{*.ts,*.js,*jsx,*tsx,*.json,*.code-workspace}]
insert_final_newline = true
indent_style = space
indent_size = 2
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.gitignore
/e2e/**
/helpers/**
/perf/**
**/node_modules/**
*.d.ts
/packages/*/testResources/**
118 changes: 118 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

module.exports = {
env: {
node: true
},
parserOptions: {
sourceType: 'module',
project: [require.resolve('./tsconfig.lint.json')]
},
parser: '@typescript-eslint/parser',
extends: ['prettier', 'eslint:recommended'],
plugins: ['@typescript-eslint', 'prettier'],
rules: {
'prettier/prettier': ['error'],
'sort-imports': 'off', // No auto-fix!
'no-case-declarations': 'off',
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': [
'error',
{
default: 'array-simple'
}
],
'@typescript-eslint/await-thenable': 'off',
'@typescript-eslint/ban-ts-ignore': 'error',
'@typescript-eslint/ban-types': 'error',
'brace-style': 'off',
'@typescript-eslint/brace-style': 'error',
camelcase: 'off',
'@typescript-eslint/camelcase': 'error',
'@typescript-eslint/class-name-casing': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'func-call-spacing': 'off',
'@typescript-eslint/func-call-spacing': 'error',
'@typescript-eslint/generic-type-naming': 'off',
indent: 'off',
'@typescript-eslint/indent': 'off',
'@typescript-eslint/interface-name-prefix': ['error', 'never'],
'@typescript-eslint/member-delimiter-style': 'off',
'@typescript-eslint/member-naming': 'error',
'@typescript-eslint/member-ordering': 'off',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'error',
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'no-extra-parens': 'off',
'@typescript-eslint/no-extra-parens': ['error', 'functions'],
'@typescript-eslint/no-extraneous-class': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-inferrable-types': 'off',
'no-magic-numbers': 'off',
'@typescript-eslint/no-magic-numbers': 'off',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-type-alias': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/no-unnecessary-qualifier': 'error',
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/prefer-regexp-exec': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/promise-function-async': 'off',
quotes: 'off',
'@typescript-eslint/quotes': ['error', 'single', { avoidEscape: true }],
'@typescript-eslint/require-array-sort-compare': 'error',
'require-await': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-plus-operands': 'error',
semi: 'off',
'@typescript-eslint/semi': 'off',
'@typescript-eslint/strict-boolean-expressions': 'off',
'@typescript-eslint/triple-slash-reference': 'error',
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/typedef': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/unified-signatures': 'error'
},
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'no-undef': 'off',
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
overrides: {
constructors: 'no-public',
properties: 'explicit'
}
}
]
}
}
]
};
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ node_modules
lerna-debug.log
npm-debug.log
stryker.log
tslint.log
lint.log

coverage
reports
Expand Down
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 150,
"singleQuote": true
}
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_js:
- 'node'
- '8'
before_script:
- npm prune
- npm ls
sudo: 'false'
addons:
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Get in touch with us through twitter or via the [Stryker gitter](https://gitter.

## Code style

Please adhere to our [editorconfig](https://editorconfig.org) and [tslint](https://palantir.github.io/tslint/) rules. If you're using vscode, please install the following extensions:
Please adhere to our [editorconfig](https://editorconfig.org) and [eslint](https://eslint.org/) rules. If you're using vscode, please install the following extensions:

* The [editorconfig extension](https://github.com/editorconfig/editorconfig-vscode#editorconfig-for-visual-studio-code)
* The [tslint extension](https://github.com/Microsoft/vscode-tslint) (at least v1.0.0)
* The [eslint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)

We configured the tslint extension to run on save in or [vscode workspace](#vscode-environment-configuration).

Expand Down Expand Up @@ -50,7 +50,7 @@ We've chosen to **check in in our vscode configuration**. This makes development
We recommend you to install the following plugins:

* [editorconfig](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig), to adhere to our white spacing rules.
* [tslint](https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-tslint-plugin), to adhere to our tslint rules (as well as having auto fix-on-save)
* [eslint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
* [code spell checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker), no particular reason, just prevent common typo's.

After cloning this repo, open the workspace with `$ code workspace.code-workspace` (or open code and use file -> Open Workspace...).
Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
"@types/rimraf": "2.0.2",
"@types/sinon": "5.0.5",
"@types/sinon-chai": "3.2.3",
"@typescript-eslint/eslint-plugin": "~2.3.0",
"@typescript-eslint/parser": "~2.3.0",
"acorn": "^7.0.0",
"chai": "^4.1.1",
"chai-as-promised": "^7.1.1",
"concurrently": "^5.0.0",
"cross-env": "^6.0.0",
"eslint": "~6.4.0",
"eslint-config-prettier": "~6.3.0",
"eslint-plugin-import": "~2.18.2",
"eslint-plugin-prettier": "~3.1.0",
"execa": "^2.0.3",
"glob": "^7.1.1",
"if-node-version": "^1.1.1",
Expand All @@ -30,25 +36,21 @@
"link-parent-bin": "~1.0.0",
"mocha": "^6.1.2",
"nyc": "^14.0.0",
"prettier": "~1.18.2",
"rimraf": "^3.0.0",
"rxjs": "^6.4.0",
"sinon": "^7.2.0",
"sinon-chai": "^3.2.0",
"source-map-support": "^0.5.6",
"tslint": "~5.20.0",
"tslint-consistent-codestyle": "~1.15.1",
"typescript": "~3.5.3"
},
"prettier": {
"singleQuote": true
},
"scripts": {
"all": "npm run clean && npm run lint && npm run build && npm run test && npm run e2e",
"postinstall": "lerna bootstrap --no-ci && link-parent-bin",
"lint-info": "tslint --out tslint.log --project tsconfig.lint.json",
"lint-fix": "tslint --fix --project tsconfig.lint.json",
"lint": "eslint . --ext .ts,.tsx",
"lint:log": "eslint . --ext .ts,.tsx -f compact -o lint.log",
"lint:fix": "eslint . --ext .ts,.tsx --fix",
"clean": "rimraf \"packages/api/*+(.d.ts|.js|.map)\" \"packages/*/+(test|src)/**/*+(.d.ts|.js|.map)\" \"packages/*/{.nyc_output,reports,coverage,*.tsbuildinfo}\"",
"lint": "tslint -p tsconfig.lint.json",
"build": "tsc -b && lerna run build",
"test": "npm run mocha",
"mocha": "lerna run test --stream --concurrency 4",
Expand Down
3 changes: 3 additions & 0 deletions packages/api/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../.eslintrc.js"
}
1 change: 0 additions & 1 deletion packages/api/src/config/Config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { LogLevel, MutationScoreThresholds, MutatorDescriptor, StrykerOptions } from '../../core';

export default class Config implements StrykerOptions {

[customConfig: string]: any;

public files: string[];
Expand Down
5 changes: 2 additions & 3 deletions packages/api/src/core/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Represents a file within Stryker. Could be a strictly in-memory file.
*/
export default class File {

private _textContent: string | undefined;
private readonly _content: Buffer;

Expand All @@ -23,14 +22,14 @@ export default class File {
/**
* Gets the underlying content as buffer.
*/
get content(): Buffer {
public get content(): Buffer {
return this._content;
}

/**
* Gets the underlying content as string using utf8 encoding.
*/
get textContent(): string {
public get textContent(): string {
if (!this._textContent) {
this._textContent = this.content.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mutant/Mutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { File } from '../../core';
import Mutant from './Mutant';

export default interface Mutator {
mutate(inputFiles: ReadonlyArray<File>): ReadonlyArray<Mutant>;
mutate(inputFiles: readonly File[]): readonly Mutant[];
}
2 changes: 1 addition & 1 deletion packages/api/src/plugin/Contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface TranspilerPluginContext extends OptionsContext {
* The dependency injection context for a `TestRunnerPlugin`
*/
export interface TestRunnerPluginContext extends OptionsContext {
[commonTokens.sandboxFileNames]: ReadonlyArray<string>;
[commonTokens.sandboxFileNames]: readonly string[];
}

/**
Expand Down
23 changes: 15 additions & 8 deletions packages/api/src/plugin/Plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import { PluginKind } from './PluginKind';
* Represents a StrykerPlugin
*/
export type Plugin<TPluginKind extends PluginKind> =
FactoryPlugin<TPluginKind, InjectionToken<PluginContexts[TPluginKind]>[]> | ClassPlugin<TPluginKind, InjectionToken<PluginContexts[TPluginKind]>[]>;
| FactoryPlugin<TPluginKind, Array<InjectionToken<PluginContexts[TPluginKind]>>>
| ClassPlugin<TPluginKind, Array<InjectionToken<PluginContexts[TPluginKind]>>>;

/**
* Represents a plugin that is created with a factory method
*/
export interface FactoryPlugin<TPluginKind extends PluginKind, Tokens extends InjectionToken<PluginContexts[TPluginKind]>[]> {
export interface FactoryPlugin<TPluginKind extends PluginKind, Tokens extends Array<InjectionToken<PluginContexts[TPluginKind]>>> {
readonly kind: TPluginKind;
readonly name: string;
/**
Expand All @@ -29,7 +30,7 @@ export interface FactoryPlugin<TPluginKind extends PluginKind, Tokens extends In
/**
* Represents a plugin that is created by instantiating a class.
*/
export interface ClassPlugin<TPluginKind extends PluginKind, Tokens extends InjectionToken<PluginContexts[TPluginKind]>[]> {
export interface ClassPlugin<TPluginKind extends PluginKind, Tokens extends Array<InjectionToken<PluginContexts[TPluginKind]>>> {
readonly kind: TPluginKind;
readonly name: string;
/**
Expand All @@ -45,8 +46,11 @@ export interface ClassPlugin<TPluginKind extends PluginKind, Tokens extends Inje
* @param name The name of the plugin
* @param injectableClass The class to be instantiated for the plugin
*/
export function declareClassPlugin<TPluginKind extends PluginKind, Tokens extends InjectionToken<PluginContexts[TPluginKind]>[]>(kind: TPluginKind, name: string, injectableClass: InjectableClass<PluginContexts[TPluginKind], PluginInterfaces[TPluginKind], Tokens>):
ClassPlugin<TPluginKind, Tokens> {
export function declareClassPlugin<TPluginKind extends PluginKind, Tokens extends Array<InjectionToken<PluginContexts[TPluginKind]>>>(
kind: TPluginKind,
name: string,
injectableClass: InjectableClass<PluginContexts[TPluginKind], PluginInterfaces[TPluginKind], Tokens>
): ClassPlugin<TPluginKind, Tokens> {
return {
injectableClass,
kind,
Expand All @@ -60,8 +64,11 @@ export function declareClassPlugin<TPluginKind extends PluginKind, Tokens extend
* @param name The name of the plugin
* @param factory The factory used to instantiate the plugin
*/
export function declareFactoryPlugin<TPluginKind extends PluginKind, Tokens extends InjectionToken<PluginContexts[TPluginKind]>[]>(kind: TPluginKind, name: string, factory: InjectableFunction<PluginContexts[TPluginKind], PluginInterfaces[TPluginKind], Tokens>):
FactoryPlugin<TPluginKind, Tokens> {
export function declareFactoryPlugin<TPluginKind extends PluginKind, Tokens extends Array<InjectionToken<PluginContexts[TPluginKind]>>>(
kind: TPluginKind,
name: string,
factory: InjectableFunction<PluginContexts[TPluginKind], PluginInterfaces[TPluginKind], Tokens>
): FactoryPlugin<TPluginKind, Tokens> {
return {
factory,
kind,
Expand Down Expand Up @@ -93,5 +100,5 @@ export type Plugins = {
*/
export interface PluginResolver {
resolve<T extends keyof Plugins>(kind: T, name: string): Plugins[T];
resolveAll<T extends keyof Plugins>(kind: T): Plugins[T][];
resolveAll<T extends keyof Plugins>(kind: T): Array<Plugins[T]>;
}
1 change: 0 additions & 1 deletion packages/api/src/plugin/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Define a string literal.
* @param value Token literal
Expand Down
1 change: 0 additions & 1 deletion packages/api/src/report/MutantStatus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
enum MutantStatus {

/**
* The status of a survived mutant, because it was not covered by any test.
*/
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/report/Reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import SourceFile from './SourceFile';
* Represents a reporter which can report during or after a Stryker run
*/
interface Reporter {

/**
* Called when a source file was loaded
* @param file The immutable source file
Expand All @@ -25,7 +24,7 @@ interface Reporter {
* Called when mutants are matched with tests
* @param results The immutable array of mutants
*/
onAllMutantsMatchedWithTests?(results: ReadonlyArray<MatchedMutant>): void;
onAllMutantsMatchedWithTests?(results: readonly MatchedMutant[]): void;

/**
* Called when a mutant was tested
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/report/ScoreResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Represents a score result of a file or directory
*/
interface ScoreResult {

/**
* The file or directory name of this score result node
*/
Expand All @@ -22,7 +21,7 @@ interface ScoreResult {
* Any child directory/file score result nodes
* If this score result represents a file, the length will be 0
*/
readonly childResults: ReadonlyArray<ScoreResult>;
readonly childResults: readonly ScoreResult[];

/**
* The total number of mutants that were killed
Expand Down
1 change: 0 additions & 1 deletion packages/api/src/test_framework/TestFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import TestSelection from './TestSelection';
* Represents a TestFramework which can select one or more tests to be executed.
*/
interface TestFramework {

/**
* Creates a code fragment which, if included in a test run,
* is ran before a particular test is run.
Expand Down
Loading

0 comments on commit 9c693ee

Please sign in to comment.