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

feat: Support eslint@6 #645

Merged
merged 7 commits into from Jul 21, 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
2 changes: 0 additions & 2 deletions azure-pipelines.yml
Expand Up @@ -62,8 +62,6 @@ jobs:
node_version: 10.x
node_8_x:
node_version: 8.x
node_6_x:
node_version: 6.x
steps:
- task: NodeTool@0
inputs:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -65,7 +65,7 @@
"all-contributors-cli": "^6.0.0",
"babel-code-frame": "^6.26.0",
"cz-conventional-changelog": "2.1.0",
"eslint": "^5.12.1",
"eslint": "^6.0.0",
"eslint-plugin-eslint-plugin": "^2.0.1",
"eslint-plugin-jest": "^22.2.2",
"glob": "7.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-tslint/package.json
Expand Up @@ -35,7 +35,7 @@
"lodash.memoize": "^4.1.2"
},
"peerDependencies": {
"eslint": "^5.0.0",
"eslint": "^5.0.0 || ^6.0.0",
"tslint": "^5.0.0"
},
"devDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion packages/eslint-plugin-tslint/tests/index.spec.ts
@@ -1,4 +1,5 @@
import { TSESLint } from '@typescript-eslint/experimental-utils';
import * as parser from '@typescript-eslint/parser';
import { readFileSync } from 'fs';
import rule, { Options } from '../src/rules/config';

Expand All @@ -13,7 +14,7 @@ const ruleTester = new TSESLint.RuleTester({
*/
project: './tests/tsconfig.json',
},
parser: '@typescript-eslint/parser',
parser: require.resolve('@typescript-eslint/parser'),
});

/**
Expand Down Expand Up @@ -146,6 +147,7 @@ describe('tslint/error', () => {
function testOutput(code: string, config: TSESLint.Linter.Config): void {
const linter = new TSESLint.Linter();
linter.defineRule('tslint/config', rule);
linter.defineParser('@typescript-eslint/parser', parser);

expect(() => linter.verify(code, config)).toThrow(
`You must provide a value for the "parserOptions.project" property for @typescript-eslint/parser`,
Expand Down Expand Up @@ -176,6 +178,7 @@ describe('tslint/error', () => {
const linter = new TSESLint.Linter();
jest.spyOn(console, 'warn').mockImplementation();
linter.defineRule('tslint/config', rule);
linter.defineParser('@typescript-eslint/parser', parser);
expect(() =>
linter.verify('foo;', {
parserOptions: {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Expand Up @@ -54,6 +54,6 @@
},
"peerDependencies": {
"@typescript-eslint/parser": "^1.9.0",
"eslint": "^5.0.0"
"eslint": "^5.0.0 || ^6.0.0"
}
}
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/array-type.ts
Expand Up @@ -72,7 +72,8 @@ function typeNeedsParentheses(node: TSESTree.Node): boolean {
}
}

type Options = ['array' | 'generic' | 'array-simple'];
export type OptionString = 'array' | 'generic' | 'array-simple';
type Options = [OptionString];
type MessageIds =
| 'errorStringGeneric'
| 'errorStringGenericSimple'
Expand Down
Expand Up @@ -8,7 +8,6 @@ import {
AST_TOKEN_TYPES,
TSESLint,
} from '@typescript-eslint/experimental-utils';
import { createGlobalLinebreakMatcher } from 'eslint/lib/util/ast-utils';
import {
isOpeningParenToken,
isClosingParenToken,
Expand All @@ -26,6 +25,10 @@ import { OffsetStorage } from './OffsetStorage';
import { TokenInfo } from './TokenInfo';
import { createRule, ExcludeKeys, RequireKeys } from '../../util';

function createGlobalLinebreakMatcher() {
return /\r\n|[\r\n\u2028\u2029]/gu;
}

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
Expand Down
43 changes: 41 additions & 2 deletions packages/eslint-plugin/tests/RuleTester.ts
@@ -1,8 +1,47 @@
import { TSESLint, ESLintUtils } from '@typescript-eslint/experimental-utils';
import * as path from 'path';

// re-export the RuleTester from here to make it easier to do the tests
const RuleTester = TSESLint.RuleTester;
const parser = '@typescript-eslint/parser';

type RuleTesterConfig = Omit<TSESLint.RuleTesterConfig, 'parser'> & {
parser: typeof parser;
};
class RuleTester extends TSESLint.RuleTester {
// as of eslint 6 you have to provide an absolute path to the parser
// but that's not as clean to type, this saves us trying to manually enforce
// that contributors require.resolve everything
constructor(options: RuleTesterConfig) {
super({
...options,
parser: require.resolve(options.parser),
});
}

// as of eslint 6 you have to provide an absolute path to the parser
// If you don't do that at the test level, the test will fail somewhat cryptically...
// This is a lot more explicit
run<TMessageIds extends string, TOptions extends Readonly<any[]>>(
name: string,
rule: TSESLint.RuleModule<TMessageIds, TOptions>,
tests: TSESLint.RunTests<TMessageIds, TOptions>,
): void {
const errorMessage = `Do not set the parser at the test level unless you want to use a parser other than ${parser}`;
tests.valid.forEach(test => {
if (typeof test !== 'string') {
if (test.parser === parser) {
throw new Error(errorMessage);
}
}
});
tests.invalid.forEach(test => {
if (test.parser === parser) {
throw new Error(errorMessage);
}
});

super.run(name, rule, tests);
}
}

function getFixturesRootDir() {
return path.join(process.cwd(), 'tests/fixtures/');
Expand Down