Skip to content

Commit

Permalink
refactor(strictness): Remove unused parameters (#1214)
Browse files Browse the repository at this point in the history
Enable `noUnusedParameters` ts config option and remove the unused parameters.
  • Loading branch information
lucaslago authored and nicojs committed Oct 28, 2018
1 parent c7d32c1 commit 2732895
Show file tree
Hide file tree
Showing 32 changed files with 48 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('BabelTranspiler', () => {

describe('constructor', () => {

function arrangeHappyFlow(transformResult: babel.BabelFileResult & { ignored?: boolean } = { code: 'code' }) {
function arrangeHappyFlow() {
babelConfigReaderMock.readConfig.returns(babelOptions);
sut = new BabelTranspiler({ config, produceSourceMaps: false });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function annotateCode(sourceFile: SourceFile, numberedMutants: NumberedMutant[])
</a>
+ <span class='badge badge-info stryker-mutant-replacement' hidden='hidden' data-mutant={m.index}>{escapeHtml(m.mutant.replacement)}</span>);
const originalCodeStartAnnotations = mutantsStarting.map(m => `<span class="stryker-original-code" data-mutant="${m.index}">`);
const originalCodeEndAnnotations = mutantsEnding.map(m => '</span>');
const originalCodeEndAnnotations = mutantsEnding.map(() => '</span>');

return `${backgroundColorEndAnnotation}${originalCodeEndAnnotations.join('')}${mutantsAnnotations.join('')}${originalCodeStartAnnotations.join('')}${backgroundColorAnnotation}${escapeHtml(char)}`;
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class ConditionalExpressionMutator implements NodeMutator {

constructor() { }

public mutate(node: types.Node, copy: <T extends types.Node>(obj: T, deep?: boolean) => T): types.Node[] | void {
public mutate(node: types.Node): types.Node[] | void {
if (types.isConditionalExpression(node)) {
return [
NodeGenerator.createBooleanLiteralNode(node.test, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class DoStatementMutator implements NodeMutator {

constructor() { }

public mutate(node: types.Node, copy: <T extends types.Node>(obj: T, deep?: boolean) => T): types.Node[] | void {
public mutate(node: types.Node): types.Node[] | void {
if (types.isDoWhileStatement(node)) {
return [NodeGenerator.createBooleanLiteralNode(node.test, false)];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class IfStatementMutator implements NodeMutator {

constructor() { }

public mutate(node: types.Node, copy: <T extends types.Node>(obj: T, deep?: boolean) => T): types.Node[] | void {
public mutate(node: types.Node): types.Node[] | void {
if (types.isIfStatement(node)) {
return [
NodeGenerator.createBooleanLiteralNode(node.test, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class WhileStatementMutator implements NodeMutator {

constructor() { }

public mutate(node: types.Node, copy: <T extends types.Node>(obj: T, deep?: boolean) => T): types.Node[] | void {
public mutate(node: types.Node): types.Node[] | void {
if (types.isWhileStatement(node)) {
return [NodeGenerator.createBooleanLiteralNode(node.test, false)];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('JestPromiseTestAdapter', () => {

beforeEach(() => {
runCLIStub = sinon.stub(jest, 'runCLI');
runCLIStub.callsFake((config: object, projectRootArray: string[]) => Promise.resolve({
runCLIStub.callsFake((config: object) => Promise.resolve({
config,
result: 'testResult'
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ describe('createReactTsJestConfig', () => {

beforeEach(() => {
loaderStub = sinon.stub(loader, 'require');
loaderStub.returns((resolve: Function, projectRoot: string, ejected: boolean) => {
return 'jestConfig';
});
loaderStub.returns(() => 'jestConfig');
});

it('should call the loader with the react jest config generator', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/stryker-karma-runner/src/StrykerReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class StrykerReporter extends EventEmitter implements karma.Repor
return this._instance;
}

public onSpecComplete(browser: any, spec: KarmaSpec) {
public onSpecComplete(_browser: any, spec: KarmaSpec) {
const name = spec.suite.reduce((name, suite) => name + suite + ' ', '') + spec.description;
let status = TestStatus.Failed;
if (spec.skipped) {
Expand All @@ -53,15 +53,15 @@ export default class StrykerReporter extends EventEmitter implements karma.Repor
this.emit('run_complete', this.collectRunState(runResult));
}

public onBrowserComplete(browser: any, result: { coverage: CoverageCollection | CoverageCollectionPerTest }) {
public onBrowserComplete(_browser: any, result: { coverage: CoverageCollection | CoverageCollectionPerTest }) {
this.emit('coverage_report', result.coverage);
}

public onBrowsersReady() {
this.emit('browsers_ready');
}

public onBrowserError(browser: any, error: any) {
public onBrowserError(_browser: any, error: any) {
// Karma 2.0 has different error messages
if (error.message) {
this.emit('browser_error', error.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('stryker-karma.conf.js', () => {

it('should set basePath to location of karma.conf.js', () => {
sut.setGlobals({ karmaConfigFile: '../foobar.conf.js' });
requireModuleStub.returns((config: Config) => { /* noop */ });
requireModuleStub.returns(() => { /* noop */ });
sut(config);
expect(config).deep.include({
basePath: path.resolve('../'),
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker-mocha-runner/src/MochaTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class MochaTestRunner implements TestRunner {
this.addTestHooks(mocha, testHooks);
this.addFiles(mocha);
try {
mocha.run((failures: number) => {
mocha.run(() => {
const reporter = StrykerMochaReporter.CurrentInstance;
if (reporter) {
const result: RunResult = reporter.runResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class ArrowFunctionMutator extends NodeMutator<ts.ArrowFunction>
return node.kind === ts.SyntaxKind.ArrowFunction;
}

protected identifyReplacements(fn: ts.ArrowFunction, sourceFile: ts.SourceFile): NodeReplacement[] {
protected identifyReplacements(fn: ts.ArrowFunction): NodeReplacement[] {
if (fn.body.kind === ts.SyntaxKind.Block) {
// This case is already handled by the BlockMutator.
return [];
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker-typescript/src/mutator/BlockMutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class BlockMutator extends NodeMutator<ts.Block> {
return node.kind === ts.SyntaxKind.Block;
}

protected identifyReplacements(block: ts.Block, sourceFile: ts.SourceFile): NodeReplacement[] {
protected identifyReplacements(block: ts.Block): NodeReplacement[] {
if (block.statements.length) {
return [{ node: block, replacement: '{}' }];
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class ConditionalExpressionMutator extends NodeMutator<ts.Conditi
return node.kind === ts.SyntaxKind.ConditionalExpression;
}

protected identifyReplacements(node: ts.ConditionalExpression, sourceFile: ts.SourceFile): NodeReplacement[] {
protected identifyReplacements(node: ts.ConditionalExpression): NodeReplacement[] {
return [
{ node: node.condition, replacement: 'false' },
{ node: node.condition, replacement: 'true' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class DoStatementMutator extends NodeMutator<ts.DoStatement> {
return node.kind === ts.SyntaxKind.DoStatement;
}

protected identifyReplacements(node: ts.DoStatement, sourceFile: ts.SourceFile): NodeReplacement[] {
protected identifyReplacements(node: ts.DoStatement): NodeReplacement[] {
return [{ node: node.expression, replacement: 'false' }];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class IfStatementMutator extends NodeMutator<ts.IfStatement> {
return node.kind === ts.SyntaxKind.IfStatement;
}

protected identifyReplacements(ifStatement: ts.IfStatement, sourceFile: ts.SourceFile): NodeReplacement[] {
protected identifyReplacements(ifStatement: ts.IfStatement): NodeReplacement[] {
return [
{ node: ifStatement.expression, replacement: 'true' },
{ node: ifStatement.expression, replacement: 'false' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class ObjectLiteralMutator extends NodeMutator<ts.ObjectLiteralEx
return node.kind === ts.SyntaxKind.ObjectLiteralExpression;
}

protected identifyReplacements(o: ts.ObjectLiteralExpression, sourceFile: ts.SourceFile): NodeReplacement[] {
protected identifyReplacements(o: ts.ObjectLiteralExpression): NodeReplacement[] {
if (o.properties.length > 0) {
return [{ node: o, replacement: '{}' }];
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class WhileStatementMutator extends NodeMutator<ts.WhileStatement
return node.kind === ts.SyntaxKind.WhileStatement;
}

protected identifyReplacements(node: ts.WhileStatement, sourceFile: ts.SourceFile): NodeReplacement[] {
protected identifyReplacements(node: ts.WhileStatement): NodeReplacement[] {
return [{ node: node.expression, replacement: 'false' }];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ describe('TypescriptConfigEditor edit', () => {
it('should log errors on failure during load of extending file', () => {
readFileSyncStub.returns(`{ "extends": "./parent.tsconfig.json" }`);
config[CONFIG_KEY] = 'tsconfig.json';
sut.edit(config, parseConfigHost({ readFile: _ => `invalid json` }));
sut.edit(config, parseConfigHost({ readFile: () => `invalid json` }));
expect(loggerStub.error).calledWithMatch(match('error TS1005: \'{\' expected.'));
});

function parseConfigHost(overrides?: Partial<ts.ParseConfigHost>): ts.ParseConfigHost {
const defaults: ts.ParseConfigHost = {
fileExists: _ => true,
readDirectory: dir => ['file1.ts', 'file2.ts'],
readFile: _ => '',
fileExists: () => true,
readDirectory: () => ['file1.ts', 'file2.ts'],
readFile: () => '',
useCaseSensitiveFileNames: true
};
return Object.assign({}, defaults, overrides);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class WebpackCompiler {
}

public emit(): Promise<File[]> {
return this.compile().then(stats => {
return this.compile().then(() => {
const outputFiles = this._outputFS.collectFiles();
this._outputFS.purge();
return outputFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ export default class OutputFileSystem implements webpack.OutputFileSystem {
new File(fileName, this._files[fileName]));
}

public mkdirp(dir: string, opts: any, cb?: Callback<string>): void {
public mkdirp(_dir: string, opts: any, cb?: Callback<string>): void {
const callback: Callback<string> = cb || opts;
callback(null);
}

public rmdir(name: PathLike, callback: EmptyCallback): void {
public rmdir(_name: PathLike, callback: EmptyCallback): void {
callback();
}

public mkdir(name: PathLike, callback: EmptyCallback): void {
public mkdir(_name: PathLike, callback: EmptyCallback): void {
callback();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/stryker-webpack-transpiler/test/helpers/producers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Configuration, Stats } from 'webpack';
import { Configuration } from 'webpack';
import { WebpackCompilerMock } from './mockInterfaces';
import * as sinon from 'sinon';
import { StrykerWebpackConfig } from '../../src/WebpackTranspiler';
Expand Down Expand Up @@ -44,6 +44,6 @@ export function createWebpackMock(): WebpackCompilerMock {
context: { fileSystem: {} },
normal: { fileSystem: {} }
},
run: (callback: (err: Error, stats: Stats) => void) => { }
run: () => { }
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import * as fs from 'fs';
import * as path from 'path';
import { expect, assert } from 'chai';
import ConfigLoader from '../../../src/compiler/ConfigLoader';
import { Configuration, Compiler, Plugin } from 'webpack';
import { Configuration, Plugin } from 'webpack';
import { createStrykerWebpackConfig } from '../../helpers/producers';

class FooPlugin implements Plugin { public foo = true; public apply(compiler: Compiler): void { } }
class ProgressPlugin implements Plugin { public apply(compiler: Compiler): void { } }
class BarPlugin implements Plugin { public bar = true; public apply(compiler: Compiler): void { } }
class FooPlugin implements Plugin { public foo = true; public apply() { } }
class ProgressPlugin implements Plugin { public apply() { } }
class BarPlugin implements Plugin { public bar = true; public apply() { } }

describe('ConfigLoader', () => {
let sut: ConfigLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('WebpackCompiler', () => {
const textFiles = createFakeTextFileArray();
sut.writeFilesToFs(textFiles);

textFiles.forEach((textFile, index) => {
textFiles.forEach(textFile => {
expect(inputFileSystemMock.writeFileSync).calledWith(textFile.name);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('InputFileSystem', () => {

it('should forward to memory fs', done => {
memoryFSMock.stat.callsArgWith(1, undefined, 'foobar');
sut.stat('arg1', (error, value) => {
sut.stat('arg1', (_error, value) => {
expect(value).eq('foobar');
expect(innerFSMock.stat).not.called;
done();
Expand All @@ -59,7 +59,7 @@ describe('InputFileSystem', () => {
memoryFSMock.stat.callsArgOnWith(1, sut, new Error('foobar'));

// Act
sut.stat('foo/bar/not/exits', (err, stats) => {
sut.stat('foo/bar/not/exits', err => {

// Assert
expect(err).eq(expectedError);
Expand All @@ -72,7 +72,7 @@ describe('InputFileSystem', () => {

it('should forward readFile to memory FS', done => {
memoryFSMock.readFile.callsArgOnWith(2, sut, undefined, 'foobar');
sut.readFile('path', {}, (error: Error, value: string) => {
sut.readFile('path', {}, (_error: Error, value: string) => {
expect(value).eq('foobar');
expect(memoryFSMock.readFile).calledWith('path');
expect(innerFSMock.readFile).not.called;
Expand All @@ -83,7 +83,7 @@ describe('InputFileSystem', () => {
it('should forward to real FS if memory-fs gave an error', done => {
memoryFSMock.readFile.callsArgOnWith(1, sut, new Error('foobar'));
innerFSMock.readFile.callsArgWith(1, undefined, 'the content');
sut.readFile('foobar', (error: Error, content: string) => {
sut.readFile('foobar', (_error: Error, content: string) => {
expect(content).eq('the content');
expect(innerFSMock.readFile).calledWith('foobar');
done();
Expand All @@ -97,7 +97,7 @@ describe('InputFileSystem', () => {
memoryFSMock.readFile.callsArgOnWith(1, sut, new Error('foobar'));

// Act
sut.readFile('foo/bar/not/exits', (error: Error, content: string) => {
sut.readFile('foo/bar/not/exits', (error: Error) => {

// Assert
expect(error).eq(expectedError);
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/MutantTestMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default class MutantTestMatcher {
}
}

private isCoveragePerTestResult(coverage: CoverageCollection | CoveragePerTestResult | undefined): coverage is CoveragePerTestResult {
private isCoveragePerTestResult(_coverage: CoverageCollection | CoveragePerTestResult | undefined): _coverage is CoveragePerTestResult {
return this.options.coverageAnalysis === 'perTest';
}
}
2 changes: 1 addition & 1 deletion packages/stryker/src/reporters/ClearTextScoreTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Column {
return this.pad(this.header);
}

protected color(score: ScoreResult) {
protected color(_score: ScoreResult) {
return (input: string) => input;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/reporters/DashboardReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class DashboardReporter implements Reporter {
private readonly ciProvider = determineCIProvider();

constructor(
setting: StrykerOptions,
_setting: StrykerOptions,
private readonly dashboardReporterClient: DashboardReporterClient = new DashboardReporterClient()
) { }

Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/test/integration/child-proxy/Echo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class Echo {

public exit(code: number) {
process.exit(code);
return new Promise(res => {/*never resolve*/ });
return new Promise(() => {/*never resolve*/ });
}

public readFile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('ES5Mutator', () => {

class StubMutator implements NodeMutator {
public name: 'stub';
public applyMutations(node: IdentifiedNode, copy: (obj: any, deep?: boolean) => any): IdentifiedNode[] {
public applyMutations(node: IdentifiedNode): IdentifiedNode[] {
const nodes: IdentifiedNode[] = [];
if (node.type === Syntax.BinaryExpression) {
// eg: '1 * 2': push child node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('TimeoutDecorator', () => {
});

it('should handle timeouts', () => {
testRunner1.run.returns(new Promise<string>(res => { }));
testRunner1.run.returns(new Promise<string>(() => { }));
const runPromise = sut.run({ timeout: 20 });
clock.tick(20);
return expect(runPromise.then(result => {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"alwaysStrict": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"noUnusedParameters": true,
"lib": [
"es5",
"es2015.promise",
Expand All @@ -23,4 +24,4 @@
"es2015.proxy"
]
}
}
}

0 comments on commit 2732895

Please sign in to comment.