Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(typescript-estree): add EXPERIMENTAL_useProjectService option to use TypeScript project service#6754

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
37 commits
Select commitHold shift + click to select a range
550465b
WIP: createProjectService
JoshuaKGoldbergMar 24, 2023
6ea9f07
Merge branch 'v6' into create-project-service
JoshuaKGoldbergApr 16, 2023
05f4d99
Collected updates: reuse program; lean more into tsserver
JoshuaKGoldbergApr 16, 2023
1fed323
chore: fix website config.ts type checking
JoshuaKGoldbergApr 16, 2023
ecd5d3d
Spell checking
JoshuaKGoldbergApr 16, 2023
78f8c4a
remove .only
JoshuaKGoldbergApr 17, 2023
76acaeb
Cleaned up todo comments in code and properly restrict new option
JoshuaKGoldbergApr 18, 2023
a68dece
Added separate test run in CI for experimental option
JoshuaKGoldbergApr 18, 2023
6f6f02a
fix: no node-version
JoshuaKGoldbergApr 18, 2023
e43145f
Remove process.env manual set
JoshuaKGoldbergApr 18, 2023
214fc8d
Fix linter config.ts
JoshuaKGoldbergApr 18, 2023
a2f71a7
Tweaked project creation to try to explicitly set cwd
JoshuaKGoldbergApr 18, 2023
4ffaffa
Progress on updating unit tests for absolute paths
JoshuaKGoldbergApr 24, 2023
20d9f82
fix: add missing clearTSServerProjectService
JoshuaKGoldbergApr 24, 2023
6ef8498
Add more path relativity fixes
JoshuaKGoldbergApr 25, 2023
195462d
Lint fixes and watch program relativity
JoshuaKGoldbergApr 25, 2023
0db7485
No, not always true
JoshuaKGoldbergApr 25, 2023
b583bb3
Fix around semanticInfo.test.ts
JoshuaKGoldbergApr 25, 2023
5b9ca22
Switch snapshot to inline
JoshuaKGoldbergApr 25, 2023
a9aec01
perf: only openExternalProject once per project
JoshuaKGoldbergApr 27, 2023
4ab1b3d
Merge branch 'v6' into create-project-service
JoshuaKGoldbergApr 27, 2023
be6cc5d
Revert "perf: only openExternalProject once per project"
JoshuaKGoldbergApr 27, 2023
80110c1
Reverted changes to allow alternate TSConfig names
JoshuaKGoldbergApr 27, 2023
c326886
Remove project existence checking
JoshuaKGoldbergApr 28, 2023
a5772e2
Add linting from root
JoshuaKGoldbergApr 28, 2023
128837a
Refactor CI naming a bit, and bumping to MacOS image...
JoshuaKGoldbergApr 28, 2023
4f52573
Alas, linting from root style runs out of memory
JoshuaKGoldbergApr 28, 2023
b1da422
Added a test, why not
JoshuaKGoldbergApr 28, 2023
814a8ad
fix: don't fall back to default program/project creation
JoshuaKGoldbergMay 3, 2023
a5180c7
Fixed up more test exclusions
JoshuaKGoldbergMay 3, 2023
37d3548
Move tsserver import to a require
JoshuaKGoldbergMay 3, 2023
00ddecd
rename: tsserverType -> ts
JoshuaKGoldbergMay 3, 2023
b5d76d4
Merge branch 'v6' into create-project-service
JoshuaKGoldbergMay 8, 2023
da45669
Use path.resolve, and then simplify parserSettings usage
JoshuaKGoldbergJun 13, 2023
69be30f
Merge branch 'main'
JoshuaKGoldbergJul 12, 2023
93d369c
Remove unneeded typingsInstaller
JoshuaKGoldbergJul 12, 2023
7e74202
Merge branch 'main' into create-project-service
JoshuaKGoldbergJul 15, 2023
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
32 changes: 32 additions & 0 deletions.github/workflows/ci.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -193,6 +193,38 @@ jobs:
# Sadly 1 day is the minimum
retention-days: 1

unit_tests_tsserver:
name: Run Unit Tests with Experimental TSServer
needs: [build]
runs-on: ubuntu-latest
strategy:
matrix:
package:
[
'eslint-plugin',
'eslint-plugin-internal',
'eslint-plugin-tslint',
'typescript-estree',
]
env:
COLLECT_COVERAGE: false
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Install
uses: ./.github/actions/prepare-install
with:
node-version: 18
- name: Build
uses: ./.github/actions/prepare-build
- name: Run unit tests for ${{ matrix.package }}
run: npx nx test ${{ matrix.package }} --coverage=false
env:
CI: true
TYPESCRIPT_ESLINT_EXPERIMENTAL_TSSERVER: true
Comment on lines +196 to +226
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This was a great thing to add!


website_tests:
# The NETLIFY_TOKEN secret will not be available on forks
if: github.repository_owner == 'typescript-eslint'
Expand Down
34 changes: 34 additions & 0 deletions.vscode/launch.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,6 +141,40 @@
"${workspaceFolder}/packages/scope-manager/dist/index.js",
],
},
{
"type": "node",
"request": "launch",
"name": "Jest Test Current eslint-plugin-tslint Rule",
"cwd": "${workspaceFolder}/packages/eslint-plugin-tslint/",
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
"args": [
"--runInBand",
"--no-cache",
"--no-coverage",
"${fileBasenameNoExtension}"
],
"sourceMaps": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"skipFiles": [
"${workspaceFolder}/packages/utils/src/index.ts",
"${workspaceFolder}/packages/utils/dist/index.js",
"${workspaceFolder}/packages/utils/src/ts-estree.ts",
"${workspaceFolder}/packages/utils/dist/ts-estree.js",
"${workspaceFolder}/packages/type-utils/src/index.ts",
"${workspaceFolder}/packages/type-utils/dist/index.js",
"${workspaceFolder}/packages/parser/src/index.ts",
"${workspaceFolder}/packages/parser/dist/index.js",
"${workspaceFolder}/packages/typescript-estree/src/index.ts",
"${workspaceFolder}/packages/typescript-estree/dist/index.js",
"${workspaceFolder}/packages/types/src/index.ts",
"${workspaceFolder}/packages/types/dist/index.js",
"${workspaceFolder}/packages/visitor-keys/src/index.ts",
"${workspaceFolder}/packages/visitor-keys/dist/index.js",
"${workspaceFolder}/packages/scope-manager/dist/index.js",
"${workspaceFolder}/packages/scope-manager/dist/index.js",
],
},
{
"type": "node",
"request": "launch",
Expand Down
11 changes: 10 additions & 1 deletiondocs/packages/TypeScript_ESTree.mdx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -147,6 +147,15 @@ interface ParseAndGenerateServicesOptions extends ParseOptions {
*/
errorOnTypeScriptSyntacticAndSemanticIssues?: boolean;

/**
* ***EXPERIMENTAL FLAG*** - Use this at your own risk.
*
* Whether to create a shared TypeScript server to power program creation.
*
* @see https://github.com/typescript-eslint/typescript-eslint/issues/6575
*/
EXPERIMENTAL_useProjectService?: boolean;

/**
* ***EXPERIMENTAL FLAG*** - Use this at your own risk.
*
Expand All@@ -155,7 +164,7 @@ interface ParseAndGenerateServicesOptions extends ParseOptions {
*
* This flag REQUIRES at least TS v3.9, otherwise it does nothing.
*
*See: https://github.com/typescript-eslint/typescript-eslint/issues/2094
*@see https://github.com/typescript-eslint/typescript-eslint/issues/2094
*/
EXPERIMENTAL_useSourceOfProjectReferenceRedirect?: boolean;

Expand Down
3 changes: 2 additions & 1 deletionpackages/eslint-plugin-tslint/src/rules/config.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import { ESLintUtils } from '@typescript-eslint/utils';
import path from 'path';
import type { RuleSeverity } from 'tslint';
import { Configuration } from 'tslint';

Expand DownExpand Up@@ -118,7 +119,7 @@ export default createRule<Options, MessageIds>({
context,
[{ rules: tslintRules, rulesDirectory: tslintRulesDirectory, lintFile }],
) {
const fileName = context.getFilename();
const fileName =path.resolve(context.getCwd(), context.getFilename());
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Explaining: withEXPERIMENTAL_ProjectService, relative paths might no longer match up with how the project views its root file. So switching to absolute paths is more reliable.

const sourceCode = context.getSourceCode().text;
const services = ESLintUtils.getParserServices(context);
const program = services.program;
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,6 +16,7 @@ const ruleTester = new RuleTester({
});

const withMetaParserOptions = {
EXPERIMENTAL_useProjectService: false,
tsconfigRootDir: getFixturesRootDir(),
project: './tsconfig-withmeta.json',
};
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -595,6 +595,7 @@ function getElem(dict: Record<string, { foo: string }>, key: string) {
}
`,
parserOptions: {
EXPERIMENTAL_useProjectService: false,
tsconfigRootDir: getFixturesRootDir(),
project: './tsconfig.noUncheckedIndexedAccess.json',
},
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,7 @@ function assignmentTest(
const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
EXPERIMENTAL_useProjectService: false,
project: './tsconfig.noImplicitThis.json',
tsconfigRootDir: getFixturesRootDir(),
},
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@ import { getFixturesRootDir } from '../RuleTester';
const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
EXPERIMENTAL_useProjectService: false,
project: './tsconfig.noImplicitThis.json',
tsconfigRootDir: getFixturesRootDir(),
},
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@ import { getFixturesRootDir } from '../RuleTester';
const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
EXPERIMENTAL_useProjectService: false,
project: './tsconfig.noImplicitThis.json',
tsconfigRootDir: getFixturesRootDir(),
},
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@ import { getFixturesRootDir } from '../RuleTester';
const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
EXPERIMENTAL_useProjectService: false,
project: './tsconfig.noImplicitThis.json',
tsconfigRootDir: getFixturesRootDir(),
},
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,7 @@ const ruleTester = new RuleTester({
});

const withMetaParserOptions = {
EXPERIMENTAL_useProjectService: false,
tsconfigRootDir: getFixturesRootDir(),
project: './tsconfig-withmeta.json',
};
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -204,6 +204,7 @@ const y = x!;

const ruleTesterWithNoUncheckedIndexAccess = new RuleTester({
parserOptions: {
EXPERIMENTAL_useProjectService: false,
sourceType: 'module',
tsconfigRootDir: getFixturesRootDir(),
project: './tsconfig.noUncheckedIndexedAccess.json',
Expand Down
7 changes: 4 additions & 3 deletionspackages/parser/tests/lib/parser.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import * as scopeManager from '@typescript-eslint/scope-manager';
import type { ParserOptions } from '@typescript-eslint/types';
import * as typescriptESTree from '@typescript-eslint/typescript-estree';
import path from 'path';

import { parse, parseForESLint } from '../../src/parser';

Expand DownExpand Up@@ -33,10 +34,10 @@ describe('parser', () => {
jsx: false,
},
// ts-estree specific
filePath: 'isolated-file.src.ts',
filePath: './isolated-file.src.ts',
project: 'tsconfig.json',
errorOnTypeScriptSyntacticAndSemanticIssues: false,
tsconfigRootDir:'tests/fixtures/services',
tsconfigRootDir:path.resolve(__dirname, '../fixtures/services'),
extraFileExtensions: ['.foo'],
};
parseForESLint(code, config);
Expand DownExpand Up@@ -89,7 +90,7 @@ describe('parser', () => {
filePath: 'isolated-file.src.ts',
project: 'tsconfig.json',
errorOnTypeScriptSyntacticAndSemanticIssues: false,
tsconfigRootDir:'tests/fixtures/services',
tsconfigRootDir:path.join(__dirname, '../fixtures/services'),
extraFileExtensions: ['.foo'],
};
parseForESLint(code, config);
Expand Down
2 changes: 2 additions & 0 deletionspackages/rule-tester/tests/RuleTester.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -169,6 +169,7 @@ describe('RuleTester', () => {
{
code: 'type-aware parser options should override the constructor config',
parserOptions: {
EXPERIMENTAL_useProjectService: false,
project: 'tsconfig.test-specific.json',
tsconfigRootDir: '/set/in/the/test/',
},
Expand DownExpand Up@@ -209,6 +210,7 @@ describe('RuleTester', () => {
"code": "type-aware parser options should override the constructor config",
"filename": "/set/in/the/test/file.ts",
"parserOptions": {
"EXPERIMENTAL_useProjectService": false,
"project": "tsconfig.test-specific.json",
"tsconfigRootDir": "/set/in/the/test/",
},
Expand Down
20 changes: 10 additions & 10 deletionspackages/type-utils/tests/TypeOrValueSpecifier.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -196,42 +196,42 @@ describe('TypeOrValueSpecifier', () => {
],
[
'interface Foo {prop: string}; type Test = Foo;',
{ from: 'file', name: 'Foo', path: 'tests/fixtures/file.ts' },
{ from: 'file', name: 'Foo', path: 'file.ts' },
],
[
'type Foo = {prop: string}; type Test = Foo;',
{ from: 'file', name: 'Foo', path: 'tests/fixtures/file.ts' },
{ from: 'file', name: 'Foo', path: 'file.ts' },
],
[
'interface Foo {prop: string}; type Test = Foo;',
{
from: 'file',
name: 'Foo',
path: 'tests/../tests/fixtures/////file.ts',
path: './////file.ts',
},
],
[
'type Foo = {prop: string}; type Test = Foo;',
{
from: 'file',
name: 'Foo',
path: 'tests/../tests/fixtures/////file.ts',
path: './////file.ts',
},
],
[
'interface Foo {prop: string}; type Test = Foo;',
{
from: 'file',
name: ['Foo', 'Bar'],
path: 'tests/fixtures/file.ts',
path: 'file.ts',
},
],
[
'type Foo = {prop: string}; type Test = Foo;',
{
from: 'file',
name: ['Foo', 'Bar'],
path: 'tests/fixtures/file.ts',
path: 'file.ts',
},
],
])('matches a matching file specifier: %s', runTestPositive);
Expand All@@ -247,14 +247,14 @@ describe('TypeOrValueSpecifier', () => {
],
[
'interface Foo {prop: string}; type Test = Foo;',
{ from: 'file', name: 'Foo', path: 'tests/fixtures/wrong-file.ts' },
{ from: 'file', name: 'Foo', path: 'wrong-file.ts' },
],
[
'interface Foo {prop: string}; type Test = Foo;',
{
from: 'file',
name: ['Foo', 'Bar'],
path: 'tests/fixtures/wrong-file.ts',
path: 'wrong-file.ts',
},
],
])("doesn't match a mismatched file specifier: %s", runTestNegative);
Expand DownExpand Up@@ -399,14 +399,14 @@ describe('TypeOrValueSpecifier', () => {
['type Test = RegExp;', { from: 'file', name: ['RegExp', 'BigInt'] }],
[
'type Test = RegExp;',
{ from: 'file', name: 'RegExp', path: 'tests/fixtures/file.ts' },
{ from: 'file', name: 'RegExp', path: 'file.ts' },
],
[
'type Test = RegExp;',
{
from: 'file',
name: ['RegExp', 'BigInt'],
path: 'tests/fixtures/file.ts',
path: 'file.ts',
},
],
[
Expand Down
1 change: 1 addition & 0 deletionspackages/types/src/parser-options.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,6 +47,7 @@ interface ParserOptions {
debugLevel?: DebugLevel;
errorOnTypeScriptSyntacticAndSemanticIssues?: boolean;
errorOnUnknownASTType?: boolean;
EXPERIMENTAL_useProjectService?: boolean; // purposely undocumented for now
EXPERIMENTAL_useSourceOfProjectReferenceRedirect?: boolean; // purposely undocumented for now
extraFileExtensions?: string[];
filePath?: string;
Expand Down
6 changes: 5 additions & 1 deletionpackages/typescript-estree/src/clear-caches.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
import { clearWatchCaches } from './create-program/getWatchProgramsForProjects';
import { clearProgramCache as clearProgramCacheOriginal } from './parser';
import { clearTSConfigMatchCache } from './parseSettings/createParseSettings';
import {
clearTSConfigMatchCache,
clearTSServerProjectService,
} from './parseSettings/createParseSettings';
import { clearGlobCache } from './parseSettings/resolveProjectList';

/**
Expand All@@ -14,6 +17,7 @@ export function clearCaches(): void {
clearProgramCacheOriginal();
clearWatchCaches();
clearTSConfigMatchCache();
clearTSServerProjectService();
clearGlobCache();
}

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,6 @@ import * as ts from 'typescript';
import { firstDefined } from '../node-utils';
import type { ParseSettings } from '../parseSettings';
import { describeFilePath } from './describeFilePath';
import { getWatchProgramsForProjects } from './getWatchProgramsForProjects';
import type { ASTAndDefiniteProgram } from './shared';
import { getAstFromProgram } from './shared';

Expand All@@ -28,12 +27,12 @@ const DEFAULT_EXTRA_FILE_EXTENSIONS = [
*/
function createProjectProgram(
parseSettings: ParseSettings,
programsForProjects: readonly ts.Program[],
): ASTAndDefiniteProgram | undefined {
log('Creating project program for: %s', parseSettings.filePath);

const programsForProjects = getWatchProgramsForProjects(parseSettings);
const astAndProgram = firstDefined(programsForProjects, currentProgram =>
getAstFromProgram(currentProgram, parseSettings),
getAstFromProgram(currentProgram, parseSettings.filePath),
);

// The file was either matched within the tsconfig, or we allow creating a default program
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp