Skip to content

feat: split visitor keys into their own package #2230

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

Merged
merged 1 commit into from
Jun 25, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ jobs:
env:
CI: true

- name: Run unit tests for visitor-keys
run: yarn test
working-directory: packages/visitor-keys
env:
CI: true

- name: Run unit tests for experimental-utils
run: yarn test
working-directory: packages/experimental-utils
Expand Down Expand Up @@ -257,6 +263,12 @@ jobs:
env:
CI: true

- name: Run unit tests for visitor-keys
run: yarn test
working-directory: packages/visitor-keys
env:
CI: true

- name: Run unit tests for experimental-utils
run: yarn test
working-directory: packages/experimental-utils
Expand Down
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"${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",
],
},
{
Expand Down Expand Up @@ -58,6 +60,8 @@
"${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",
],
},
{
Expand Down Expand Up @@ -86,6 +90,8 @@
"${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",
],
},
{
Expand Down Expand Up @@ -114,6 +120,8 @@
"${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",
],
},
{
Expand Down Expand Up @@ -142,6 +150,8 @@
"${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",
],
}
]
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-estree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
},
"dependencies": {
"@typescript-eslint/types": "3.4.0",
"@typescript-eslint/visitor-keys": "3.4.0",
"debug": "^4.1.1",
"eslint-visitor-keys": "^1.1.0",
"glob": "^7.1.6",
"is-glob": "^4.0.1",
"lodash": "^4.17.15",
Expand Down
4 changes: 3 additions & 1 deletion packages/typescript-estree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ export {
} from './parser';
export { ParserServices, TSESTreeOptions } from './parser-options';
export { simpleTraverse } from './simple-traverse';
export { visitorKeys } from './visitor-keys';
export * from './ts-estree';
export { clearCaches } from './create-program/createWatchProgram';

// re-export for backwards-compat
export { visitorKeys } from '@typescript-eslint/visitor-keys';

// note - cannot migrate this to an import statement because it will make TSC copy the package.json to the dist folder
export const version: string = require('../package.json').version;
2 changes: 1 addition & 1 deletion packages/typescript-estree/src/simple-traverse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { visitorKeys } from '@typescript-eslint/visitor-keys';
import { TSESTree } from './ts-estree';
import { visitorKeys } from './visitor-keys';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isValidNode(x: any): x is TSESTree.Node {
Expand Down
28 changes: 0 additions & 28 deletions packages/typescript-estree/tests/lib/visitor-keys.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/typescript-estree/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"exclude": ["tests/fixtures/**/*"],
"references": [
{ "path": "../shared-fixtures/tsconfig.build.json" },
{ "path": "../types/tsconfig.build.json" }
{ "path": "../types/tsconfig.build.json" },
{ "path": "../visitor-keys/tsconfig.build.json" }
]
}
21 changes: 21 additions & 0 deletions packages/visitor-keys/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 TypeScript ESLint and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 13 additions & 0 deletions packages/visitor-keys/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1 align="center">TypeScript-ESTree Visitor Keys</h1>

<p align="center">Visitor keys used to help traverse the TypeScript-ESTree AST</p>

<p align="center">
<img src="https://github.com/typescript-eslint/typescript-eslint/workflows/CI/badge.svg" alt="CI" />
<a href="https://www.npmjs.com/package/@typescript-eslint/visitor-keys"><img src="https://img.shields.io/npm/v/@typescript-eslint/visitor-keys.svg?style=flat-square" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/package/@typescript-eslint/visitor-keys"><img src="https://img.shields.io/npm/dm/@typescript-eslint/visitor-keys.svg?style=flat-square" alt="NPM Downloads" /></a>
</p>

## Contributing

[See the contributing guide here](../../CONTRIBUTING.md)
20 changes: 20 additions & 0 deletions packages/visitor-keys/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

// @ts-check
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
globals: {
'ts-jest': {
isolatedModules: true,
},
},
testEnvironment: 'node',
transform: {
[/^.+\.tsx?$/.source]: 'ts-jest',
},
testRegex: [/.\/tests\/.+\.test\.ts$/.source],
collectCoverage: false,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
coverageReporters: ['text-summary', 'lcov'],
};
48 changes: 48 additions & 0 deletions packages/visitor-keys/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@typescript-eslint/visitor-keys",
"version": "3.4.0",
"description": "Visitor keys used to help traverse the TypeScript-ESTree AST",
"keywords": [
"eslint",
"typescript",
"estree"
],
"engines": {
"node": "^8.10.0 || ^10.13.0 || >=11.10.1"
},
"files": [
"dist",
"package.json",
"README.md",
"LICENSE"
],
"repository": {
"type": "git",
"url": "https://github.com/typescript-eslint/typescript-eslint.git",
"directory": "packages/visitor-keys"
},
"bugs": {
"url": "https://github.com/typescript-eslint/typescript-eslint/issues"
},
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc -b tsconfig.build.json",
"clean": "tsc -b tsconfig.build.json --clean",
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
"test": "jest --coverage",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"eslint-visitor-keys": "^1.1.0"
},
"devDependencies": {
"@typescript-eslint/types": "3.4.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/typescript-eslint"
}
}
1 change: 1 addition & 0 deletions packages/visitor-keys/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { visitorKeys, VisitorKeys } from './visitor-keys';
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as eslintVisitorKeys from 'eslint-visitor-keys';

export const visitorKeys = eslintVisitorKeys.unionWith({
interface VisitorKeys {
readonly [type: string]: readonly string[] | undefined;
}

const visitorKeys: VisitorKeys = eslintVisitorKeys.unionWith({
// Additional estree nodes.
Import: [],
// ES2020
Expand Down Expand Up @@ -125,3 +129,5 @@ export const visitorKeys = eslintVisitorKeys.unionWith({
TSUnknownKeyword: [],
TSVoidKeyword: [],
});

export { visitorKeys, VisitorKeys };
31 changes: 31 additions & 0 deletions packages/visitor-keys/tests/visitor-keys.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { AST_NODE_TYPES } from '@typescript-eslint/types';
import { visitorKeys } from '../src';

const types = new Set(Object.keys(AST_NODE_TYPES));
const keys = new Set(Object.keys(visitorKeys));

describe('Every ast node type should have a visitor key defined', () => {
for (const type of types) {
it(type, () => {
expect(keys.has(type)).toBeTruthy();
});
}
});

// these keys are defined by the base eslint module, and are not covered by our AST
const IGNORED_KEYS = new Set([
'ExperimentalRestProperty',
'ExperimentalSpreadProperty',
'JSXNamespacedName',
]);
describe('Every visitor key should have an ast node type defined', () => {
for (const key of keys) {
if (IGNORED_KEYS.has(key)) {
continue;
}

it(key, () => {
expect(types.has(key)).toBeTruthy();
});
}
});
10 changes: 10 additions & 0 deletions packages/visitor-keys/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "./dist",
"rootDir": "./src",
"resolveJsonModule": true
},
"include": ["src", "typings"]
}
8 changes: 8 additions & 0 deletions packages/visitor-keys/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"composite": false,
"rootDir": "."
},
"include": ["src", "typings", "tests", "tools"]
}
12 changes: 12 additions & 0 deletions tests/integration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ services:
- /usr/eslint-plugin-tslint/tests
- ../../packages/types/:/usr/types
- /usr/types/tests
- ../../packages/visitor-keys/:/usr/visitor-keys
- /usr/types/visitor-keys
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
- ./fixtures/typescript-and-tslint-plugins-together:/usr/linked

Expand All @@ -42,6 +44,8 @@ services:
- /usr/eslint-plugin/tests
- ../../packages/types/:/usr/types
- /usr/types/tests
- ../../packages/visitor-keys/:/usr/visitor-keys
- /usr/types/visitor-keys
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
- ./fixtures/vue-sfc:/usr/linked

Expand All @@ -63,6 +67,8 @@ services:
- /usr/eslint-plugin/tests
- ../../packages/types/:/usr/types
- /usr/types/tests
- ../../packages/visitor-keys/:/usr/visitor-keys
- /usr/types/visitor-keys
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
- ./fixtures/vue-jsx:/usr/linked

Expand All @@ -84,6 +90,8 @@ services:
- /usr/eslint-plugin/tests
- ../../packages/types/:/usr/types
- /usr/types/tests
- ../../packages/visitor-keys/:/usr/visitor-keys
- /usr/types/visitor-keys
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
- ./fixtures/recommended-does-not-require-program:/usr/linked

Expand All @@ -105,6 +113,8 @@ services:
- /usr/eslint-plugin/tests
- ../../packages/types/:/usr/types
- /usr/types/tests
- ../../packages/visitor-keys/:/usr/visitor-keys
- /usr/types/visitor-keys
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
- ./fixtures/markdown:/usr/linked

Expand All @@ -126,5 +136,7 @@ services:
- /usr/eslint-plugin/tests
- ../../packages/types/:/usr/types
- /usr/types/tests
- ../../packages/visitor-keys/:/usr/visitor-keys
- /usr/types/visitor-keys
# Runtime link to all the specific integration test files, so that most updates don't require a rebuild.
- ./fixtures/eslint-v6:/usr/linked
1 change: 1 addition & 0 deletions tests/integration/fixtures/eslint-v6/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ npm install eslint@6.0.0

# Use the local volumes for our own packages
npm install $(npm pack /usr/types | tail -1)
npm install $(npm pack /usr/visitor-keys | tail -1)
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)
Expand Down
1 change: 1 addition & 0 deletions tests/integration/fixtures/markdown/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ npm install

# Use the local volumes for our own packages
npm install $(npm pack /usr/types | tail -1)
npm install $(npm pack /usr/visitor-keys | tail -1)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ npm install

# Use the local volumes for our own packages
npm install $(npm pack /usr/types | tail -1)
npm install $(npm pack /usr/visitor-keys | tail -1)
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)
Expand Down
Loading