Skip to content
Permalink
Browse files

feat(experimental-utils): expose getParserServices from utils (#1448)

* 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 982c8bc37958dfbf7bfb6e74f270866ae322995e
@@ -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<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
@@ -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.',
);
}

@@ -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>;
@@ -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,4 +1,5 @@
export * from './applyDefault';
export * from './batchedSingleLineTests';
export * from './getParserServices';
export * from './RuleCreator';
export * from './deepMerge';
@@ -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.
@@ -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)
@@ -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
@@ -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)

@@ -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)
@@ -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)

0 comments on commit 982c8bc

Please sign in to comment.
You can’t perform that action at this time.