Skip to content

Commit

Permalink
feat(experimental-utils): expose getParserServices from utils (#1448)
Browse files Browse the repository at this point in the history
* feat(experimental-utils): expose getParserServices from utils

* test: add experimental-utils to integration tests
  • Loading branch information
armano2 authored and bradzacher committed Jan 14, 2020
1 parent b529a4c commit 982c8bc
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 26 deletions.
17 changes: 2 additions & 15 deletions 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';
Expand Down Expand Up @@ -101,17 +98,7 @@ export default createRule<Options, MessageIds>({
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
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-tslint/tests/index.spec.ts
Expand Up @@ -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.',
);
}

Expand Down
10 changes: 7 additions & 3 deletions packages/eslint-plugin/src/util/index.ts
Expand Up @@ -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 };
@@ -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<ParserServices[k], undefined>;
Expand All @@ -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;
}
1 change: 1 addition & 0 deletions 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';
10 changes: 10 additions & 0 deletions tests/integration/docker-compose.yml
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions tests/integration/fixtures/markdown/test.sh
Expand Up @@ -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)
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions tests/integration/fixtures/vue-jsx/test.sh
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/integration/fixtures/vue-sfc/test.sh
Expand Up @@ -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)
Expand Down

0 comments on commit 982c8bc

Please sign in to comment.