diff --git a/packages/eslint-plugin-tslint/src/rules/config.ts b/packages/eslint-plugin-tslint/src/rules/config.ts index 05608387e79..fcfaa7e2b8f 100644 --- a/packages/eslint-plugin-tslint/src/rules/config.ts +++ b/packages/eslint-plugin-tslint/src/rules/config.ts @@ -1,7 +1,4 @@ -import { - ESLintUtils, - ParserServices, -} from '@typescript-eslint/experimental-utils'; +import { ESLintUtils } from '@typescript-eslint/experimental-utils'; import memoize from 'lodash/memoize'; import { Configuration, RuleSeverity } from 'tslint'; import { CustomLinter } from '../custom-linter'; @@ -101,17 +98,7 @@ export default createRule({ create(context) { const fileName = context.getFilename(); const sourceCode = context.getSourceCode().text; - const parserServices: ParserServices | undefined = context.parserServices; - - /** - * The user needs to have configured "project" in their parserOptions - * for @typescript-eslint/parser - */ - if (!parserServices || !parserServices.program) { - throw new Error( - `You must provide a value for the "parserOptions.project" property for @typescript-eslint/parser`, - ); - } + const parserServices = ESLintUtils.getParserServices(context); /** * The TSLint rules configuration passed in by the user diff --git a/packages/eslint-plugin-tslint/tests/index.spec.ts b/packages/eslint-plugin-tslint/tests/index.spec.ts index c69ddbeedd0..5241f8907ca 100644 --- a/packages/eslint-plugin-tslint/tests/index.spec.ts +++ b/packages/eslint-plugin-tslint/tests/index.spec.ts @@ -155,7 +155,7 @@ describe('tslint/error', () => { 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`, + 'You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.', ); } diff --git a/packages/eslint-plugin/src/util/index.ts b/packages/eslint-plugin/src/util/index.ts index cb0430c114d..7fde0f41e71 100644 --- a/packages/eslint-plugin/src/util/index.ts +++ b/packages/eslint-plugin/src/util/index.ts @@ -2,11 +2,15 @@ import { ESLintUtils } from '@typescript-eslint/experimental-utils'; export * from './astUtils'; export * from './createRule'; -export * from './getParserServices'; export * from './misc'; export * from './nullThrows'; export * from './types'; // this is done for convenience - saves migrating all of the old rules -const { applyDefault, deepMerge, isObjectNotArray } = ESLintUtils; -export { applyDefault, deepMerge, isObjectNotArray }; +const { + applyDefault, + deepMerge, + isObjectNotArray, + getParserServices, +} = ESLintUtils; +export { applyDefault, deepMerge, isObjectNotArray, getParserServices }; diff --git a/packages/eslint-plugin/src/util/getParserServices.ts b/packages/experimental-utils/src/eslint-utils/getParserServices.ts similarity index 69% rename from packages/eslint-plugin/src/util/getParserServices.ts rename to packages/experimental-utils/src/eslint-utils/getParserServices.ts index d0a18487171..65607e77290 100644 --- a/packages/eslint-plugin/src/util/getParserServices.ts +++ b/packages/experimental-utils/src/eslint-utils/getParserServices.ts @@ -1,7 +1,7 @@ -import { - ParserServices, - TSESLint, -} from '@typescript-eslint/experimental-utils'; +import { ParserServices, TSESLint } from '../'; + +const ERROR_MESSAGE = + 'You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.'; type RequiredParserServices = { [k in keyof ParserServices]: Exclude; @@ -25,9 +25,7 @@ export function getParserServices< * The user needs to have configured "project" in their parserOptions * for @typescript-eslint/parser */ - throw new Error( - 'You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.', - ); + throw new Error(ERROR_MESSAGE); } return context.parserServices as RequiredParserServices; } diff --git a/packages/experimental-utils/src/eslint-utils/index.ts b/packages/experimental-utils/src/eslint-utils/index.ts index c8069ca6fc2..72977de2003 100644 --- a/packages/experimental-utils/src/eslint-utils/index.ts +++ b/packages/experimental-utils/src/eslint-utils/index.ts @@ -1,4 +1,5 @@ export * from './applyDefault'; export * from './batchedSingleLineTests'; +export * from './getParserServices'; export * from './RuleCreator'; export * from './deepMerge'; diff --git a/tests/integration/docker-compose.yml b/tests/integration/docker-compose.yml index c3a0b450d65..a92dff5e090 100644 --- a/tests/integration/docker-compose.yml +++ b/tests/integration/docker-compose.yml @@ -13,6 +13,8 @@ services: - /usr/parser/tests - ../../packages/typescript-estree/:/usr/typescript-estree - /usr/typescript-estree/tests + - ../../packages/experimental-utils/:/usr/experimental-utils + - /usr/experimental-utils/tests - ../../packages/eslint-plugin/:/usr/eslint-plugin - /usr/eslint-plugin/tests - ../../packages/eslint-plugin-tslint/:/usr/eslint-plugin-tslint @@ -32,6 +34,8 @@ services: - /usr/parser/tests - ../../packages/typescript-estree/:/usr/typescript-estree - /usr/typescript-estree/tests + - ../../packages/experimental-utils/:/usr/experimental-utils + - /usr/experimental-utils/tests - ../../packages/eslint-plugin/:/usr/eslint-plugin - /usr/eslint-plugin/tests # Runtime link to all the specific integration test files, so that most updates don't require a rebuild. @@ -49,6 +53,8 @@ services: - /usr/parser/tests - ../../packages/typescript-estree/:/usr/typescript-estree - /usr/typescript-estree/tests + - ../../packages/experimental-utils/:/usr/experimental-utils + - /usr/experimental-utils/tests - ../../packages/eslint-plugin/:/usr/eslint-plugin - /usr/eslint-plugin/tests # Runtime link to all the specific integration test files, so that most updates don't require a rebuild. @@ -66,6 +72,8 @@ services: - /usr/parser/tests - ../../packages/typescript-estree/:/usr/typescript-estree - /usr/typescript-estree/tests + - ../../packages/experimental-utils/:/usr/experimental-utils + - /usr/experimental-utils/tests - ../../packages/eslint-plugin/:/usr/eslint-plugin - /usr/eslint-plugin/tests # Runtime link to all the specific integration test files, so that most updates don't require a rebuild. @@ -83,6 +91,8 @@ services: - /usr/parser/tests - ../../packages/typescript-estree/:/usr/typescript-estree - /usr/typescript-estree/tests + - ../../packages/experimental-utils/:/usr/experimental-utils + - /usr/experimental-utils/tests - ../../packages/eslint-plugin/:/usr/eslint-plugin - /usr/eslint-plugin/tests # Runtime link to all the specific integration test files, so that most updates don't require a rebuild. diff --git a/tests/integration/fixtures/markdown/test.sh b/tests/integration/fixtures/markdown/test.sh index 4641a6b33f4..6856a3f7c1b 100755 --- a/tests/integration/fixtures/markdown/test.sh +++ b/tests/integration/fixtures/markdown/test.sh @@ -9,6 +9,7 @@ npm install # Use the local volumes for our own packages npm install $(npm pack /usr/typescript-estree | tail -1) npm install $(npm pack /usr/parser | tail -1) +npm install $(npm pack /usr/experimental-utils | tail -1) npm install $(npm pack /usr/eslint-plugin | tail -1) # Install the latest vue-eslint-parser (this may break us occassionally, but it's probably good to get that feedback early) diff --git a/tests/integration/fixtures/recommended-does-not-require-program/test.sh b/tests/integration/fixtures/recommended-does-not-require-program/test.sh index 1fa77f5cbdf..4cf1ad5505e 100755 --- a/tests/integration/fixtures/recommended-does-not-require-program/test.sh +++ b/tests/integration/fixtures/recommended-does-not-require-program/test.sh @@ -9,6 +9,7 @@ npm install # Use the local volumes for our own packages npm install $(npm pack /usr/typescript-estree | tail -1) npm install $(npm pack /usr/parser | tail -1) +npm install $(npm pack /usr/experimental-utils | tail -1) npm install $(npm pack /usr/eslint-plugin | tail -1) # Run the linting diff --git a/tests/integration/fixtures/typescript-and-tslint-plugins-together/test.sh b/tests/integration/fixtures/typescript-and-tslint-plugins-together/test.sh index dbd94edf768..4746867a40a 100755 --- a/tests/integration/fixtures/typescript-and-tslint-plugins-together/test.sh +++ b/tests/integration/fixtures/typescript-and-tslint-plugins-together/test.sh @@ -9,6 +9,7 @@ npm install # Use the local volumes for our own packages npm install $(npm pack /usr/typescript-estree | tail -1) npm install $(npm pack /usr/parser | tail -1) +npm install $(npm pack /usr/experimental-utils | tail -1) npm install $(npm pack /usr/eslint-plugin-tslint | tail -1) npm install $(npm pack /usr/eslint-plugin | tail -1) diff --git a/tests/integration/fixtures/vue-jsx/test.sh b/tests/integration/fixtures/vue-jsx/test.sh index f59b6348fd6..30ec8940d3c 100755 --- a/tests/integration/fixtures/vue-jsx/test.sh +++ b/tests/integration/fixtures/vue-jsx/test.sh @@ -9,6 +9,7 @@ npm install # Use the local volumes for our own packages npm install $(npm pack /usr/typescript-estree | tail -1) npm install $(npm pack /usr/parser | tail -1) +npm install $(npm pack /usr/experimental-utils | tail -1) npm install $(npm pack /usr/eslint-plugin | tail -1) # Install the latest vue-eslint-parser (this may break us occassionally, but it's probably good to get that feedback early) diff --git a/tests/integration/fixtures/vue-sfc/test.sh b/tests/integration/fixtures/vue-sfc/test.sh index f59b6348fd6..30ec8940d3c 100755 --- a/tests/integration/fixtures/vue-sfc/test.sh +++ b/tests/integration/fixtures/vue-sfc/test.sh @@ -9,6 +9,7 @@ npm install # Use the local volumes for our own packages npm install $(npm pack /usr/typescript-estree | tail -1) npm install $(npm pack /usr/parser | tail -1) +npm install $(npm pack /usr/experimental-utils | tail -1) npm install $(npm pack /usr/eslint-plugin | tail -1) # Install the latest vue-eslint-parser (this may break us occassionally, but it's probably good to get that feedback early)