Skip to content

test(plugin-tslint): missing test cases for eslint-plugin-tslint #303

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

Merged
merged 2 commits into from
Feb 23, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
}
},
{
"files": ["packages/eslint-plugin/test/**/*.ts"],
"files": [
"packages/eslint-plugin/test/**/*.ts",
"packages/eslint-plugin-tslint/tests/**/*.spec.ts"
],
"rules": {
"eslint-plugin/no-identical-tests": "error"
}
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin-tslint/src/custom-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class CustomLinter extends TSLintLinter {
}

getSourceFile(fileName: string) {
const result = this.program.getSourceFile(fileName);
return result;
return this.program.getSourceFile(fileName);
}
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin-tslint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const rules = {
},
],
},
create: function(context: Rule.RuleContext) {
create(context: Rule.RuleContext) {
const fileName = context.getFilename();
const sourceCode = context.getSourceCode().text;
const parserServices: ParserServices | undefined = context.parserServices;
Expand Down
59 changes: 57 additions & 2 deletions packages/eslint-plugin-tslint/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { rules } from '../src/index';
import { RuleTester } from 'eslint';
import { rules } from '../src';
import { Linter, RuleTester } from 'eslint';
import { readFileSync } from 'fs';

const ruleTester = new RuleTester({
Expand Down Expand Up @@ -125,3 +125,58 @@ ruleTester.run('tslint/config', rules.config, {
},
],
});

describe('tslint/error', () => {
function testOutput(code: string, config: Linter.Config): void {
const linter = new Linter();
linter.defineRule('tslint/config', rules.config);

expect(() => linter.verify(code, config)).toThrow(
`You must provide a value for the "parserOptions.project" property for @typescript-eslint/parser`,
);
}

it('should error on missing project', () => {
testOutput('foo;', {
rules: {
'tslint/config': [2, tslintRulesConfig],
},
parser: '@typescript-eslint/parser',
});
});

it('should error on default parser', () => {
testOutput('foo;', {
parserOptions: {
project: `${__dirname}/test-project/tsconfig.json`,
},
rules: {
'tslint/config': [2, tslintRulesConfig],
},
});
});

it('should not crash if there is no tslint rules specified', () => {
const linter = new Linter();
jest.spyOn(console, 'warn').mockImplementation();
linter.defineRule('tslint/config', rules.config);
expect(() =>
linter.verify('foo;', {
parserOptions: {
project: `${__dirname}/test-project/tsconfig.json`,
},
rules: {
'tslint/config': [2, {}],
},
parser: '@typescript-eslint/parser',
}),
).not.toThrow();

expect(console.warn).toHaveBeenCalledWith(
expect.stringContaining(
'No valid rules have been specified for TypeScript files',
),
);
jest.resetAllMocks();
});
});