Skip to content
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

feat: Move shared types into their own package #425

Merged
merged 17 commits into from May 10, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore
Expand Up @@ -5,5 +5,4 @@ fixtures
shared-fixtures
coverage

packages/typescript-estree/src/estree
packages/eslint-plugin-tslint/tests
1 change: 1 addition & 0 deletions .eslintrc.json
Expand Up @@ -10,6 +10,7 @@
"comma-dangle": ["error", "always-multiline"],
"no-mixed-operators": "error",
"no-console": "off",
"no-dupe-class-members": "off",
"no-undef": "off",
"@typescript-eslint/indent": "off",
"@typescript-eslint/no-explicit-any": "off",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@typescript-eslint/parser": "1.7.0",
"@typescript-eslint/typescript-estree": "1.7.0",
"@typescript-eslint/util": "1.7.0",
"eslint-utils": "^1.3.1",
"regexpp": "^2.0.1",
"requireindex": "^1.2.0",
Expand Down
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import * as util from '../util';

type RuleNode =
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/array-type.ts
Expand Up @@ -2,7 +2,7 @@ import {
AST_NODE_TYPES,
AST_TOKEN_TYPES,
TSESTree,
} from '@typescript-eslint/typescript-estree';
} from '@typescript-eslint/util';
import * as util from '../util';

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-plugin/src/rules/await-thenable.ts
@@ -1,5 +1,5 @@
import * as tsutils from 'tsutils';
import * as ts from 'typescript';
import ts from 'typescript';

import * as util from '../util';

Expand All @@ -26,9 +26,9 @@ export default util.createRule({

return {
AwaitExpression(node) {
const originalNode = parserServices.esTreeNodeToTSNodeMap.get(
node,
) as ts.AwaitExpression;
const originalNode = parserServices.esTreeNodeToTSNodeMap.get<
ts.AwaitExpression
>(node);
bradzacher marked this conversation as resolved.
Show resolved Hide resolved
const type = checker.getTypeAtLocation(originalNode.expression);

if (
Expand Down
5 changes: 2 additions & 3 deletions packages/eslint-plugin/src/rules/ban-types.ts
@@ -1,5 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { ReportFixFunction } from 'ts-eslint';
import { TSESLint, TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import * as util from '../util';

type Options = [
Expand Down Expand Up @@ -94,7 +93,7 @@ export default util.createRule<Options, MessageIds>({
let customMessage = '';
const bannedCfgValue = bannedTypes[node.name];

let fix: ReportFixFunction | null = null;
let fix: TSESLint.ReportFixFunction | null = null;

if (typeof bannedCfgValue === 'string') {
customMessage += ` ${bannedCfgValue}`;
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/camelcase.ts
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import baseRule from 'eslint/lib/rules/camelcase';
import * as util from '../util';

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/class-name-casing.ts
@@ -1,5 +1,5 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import * as util from '../util';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';

export default util.createRule({
name: 'class-name-casing',
Expand Down
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import * as util from '../util';

type Options = [
Expand Down
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util';
import * as util from '../util';

type AccessibilityLevel =
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/func-call-spacing.ts
@@ -1,4 +1,4 @@
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { TSESTree } from '@typescript-eslint/util';
import { isOpeningParenToken } from 'eslint-utils';
import * as util from '../util';

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/indent.ts
Expand Up @@ -4,7 +4,7 @@
* This is done intentionally based on the internal implementation of the base indent rule.
*/

import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import baseRule from 'eslint/lib/rules/indent';
import * as util from '../util';

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/member-delimiter-style.ts
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import * as util from '../util';

type Delimiter = 'comma' | 'none' | 'semi';
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/member-naming.ts
@@ -1,4 +1,4 @@
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { TSESTree } from '@typescript-eslint/util';
import * as util from '../util';

interface Config<T = string> {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/member-ordering.ts
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import * as util from '../util';

type MessageIds = 'incorrectOrder';
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-array-constructor.ts
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import * as util from '../util';

export default util.createRule({
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-extra-parens.ts
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import baseRule from 'eslint/lib/rules/no-extra-parens';
import * as util from '../util';

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-extraneous-class.ts
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import * as util from '../util';

type Options = [
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-inferrable-types.ts
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import * as util from '../util';

type Options = [
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-magic-numbers.ts
Expand Up @@ -3,7 +3,7 @@
* @author Scott O'Hara
*/

import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import baseRule from 'eslint/lib/rules/no-magic-numbers';
import * as util from '../util';
import { JSONSchema4 } from 'json-schema';
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-misused-new.ts
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import * as util from '../util';

export default util.createRule({
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-namespace.ts
@@ -1,4 +1,4 @@
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree';
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util';
import * as util from '../util';

type Options = [
Expand Down
@@ -1,4 +1,4 @@
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree';
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util';
import * as util from '../util';

type Options = [
Expand Down
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import * as util from '../util';

type Modifier =
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-require-imports.ts
@@ -1,4 +1,4 @@
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { TSESTree } from '@typescript-eslint/util';
import * as util from '../util';

export default util.createRule({
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-this-alias.ts
@@ -1,4 +1,4 @@
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree';
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util';
import * as util from '../util';

type Options = [
Expand Down
5 changes: 2 additions & 3 deletions packages/eslint-plugin/src/rules/no-type-alias.ts
@@ -1,5 +1,4 @@
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree';
import { ReportDescriptor } from 'ts-eslint';
import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/util';
import * as util from '../util';

type Options = [
Expand Down Expand Up @@ -194,7 +193,7 @@ export default util.createRule<Options, MessageIds>({
compositionType: string | undefined,
isRoot: boolean,
type?: string,
): ReportDescriptor<MessageIds> {
): TSESLint.ReportDescriptor<MessageIds> {
if (isRoot) {
return {
node,
Expand Down
@@ -1,4 +1,4 @@
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { TSESTree } from '@typescript-eslint/util';
import ts from 'typescript';
import * as tsutils from 'tsutils';
import * as util from '../util';
Expand Down
@@ -1,4 +1,4 @@
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { TSESTree } from '@typescript-eslint/util';
import * as tsutils from 'tsutils';
import ts from 'typescript';
import * as util from '../util';
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-unused-vars.ts
@@ -1,4 +1,4 @@
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree';
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/util';
import baseRule from 'eslint/lib/rules/no-unused-vars';
import * as util from '../util';

Expand Down
25 changes: 12 additions & 13 deletions packages/eslint-plugin/src/rules/no-use-before-define.ts
@@ -1,5 +1,4 @@
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree';
import { Scope } from 'ts-eslint';
import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/util';
import * as util from '../util';

const SENTINEL_TYPE = /^(?:(?:Function|Class)(?:Declaration|Expression)|ArrowFunctionExpression|CatchClause|ImportDeclaration|ExportNamedDeclaration)$/;
Expand Down Expand Up @@ -28,23 +27,23 @@ function parseOptions(options: string | Config | null): Required<Config> {
/**
* Checks whether or not a given scope is a top level scope.
*/
function isTopLevelScope(scope: Scope.Scope): boolean {
function isTopLevelScope(scope: TSESLint.Scope.Scope): boolean {
return scope.type === 'module' || scope.type === 'global';
}

/**
* Checks whether or not a given variable is a function declaration.
*/
function isFunction(variable: Scope.Variable): boolean {
function isFunction(variable: TSESLint.Scope.Variable): boolean {
return variable.defs[0].type === 'FunctionName';
}

/**
* Checks whether or not a given variable is a class declaration in an upper function scope.
*/
function isOuterClass(
variable: Scope.Variable,
reference: Scope.Reference,
variable: TSESLint.Scope.Variable,
reference: TSESLint.Scope.Reference,
): boolean {
if (variable.defs[0].type !== 'ClassName') {
return false;
Expand All @@ -64,8 +63,8 @@ function isOuterClass(
* Checks whether or not a given variable is a variable declaration in an upper function scope.
*/
function isOuterVariable(
variable: Scope.Variable,
reference: Scope.Reference,
variable: TSESLint.Scope.Variable,
reference: TSESLint.Scope.Reference,
): boolean {
if (variable.defs[0].type !== 'Variable') {
return false;
Expand Down Expand Up @@ -102,8 +101,8 @@ function isInRange(
* - for (var a of a) {}
*/
function isInInitializer(
variable: Scope.Variable,
reference: Scope.Reference,
variable: TSESLint.Scope.Variable,
reference: TSESLint.Scope.Reference,
): boolean {
if (variable.scope !== reference.from) {
return false;
Expand Down Expand Up @@ -199,8 +198,8 @@ export default util.createRule<Options, MessageIds>({
* @param reference The reference to the variable
*/
function isForbidden(
variable: Scope.Variable,
reference: Scope.Reference,
variable: TSESLint.Scope.Variable,
reference: TSESLint.Scope.Reference,
): boolean {
if (isFunction(variable)) {
return !!options.functions;
Expand All @@ -217,7 +216,7 @@ export default util.createRule<Options, MessageIds>({
/**
* Finds and validates all variables in a given scope.
*/
function findVariablesInScope(scope: Scope.Scope): void {
function findVariablesInScope(scope: TSESLint.Scope.Scope): void {
scope.references.forEach(reference => {
const variable = reference.resolved;

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-useless-constructor.ts
@@ -1,4 +1,4 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/util';
import baseRule from 'eslint/lib/rules/no-useless-constructor';
import * as util from '../util';

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-var-requires.ts
@@ -1,4 +1,4 @@
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { AST_NODE_TYPES } from '@typescript-eslint/util';
import * as util from '../util';

type Options = [];
Expand Down
5 changes: 2 additions & 3 deletions packages/eslint-plugin/src/rules/prefer-for-of.ts
@@ -1,6 +1,5 @@
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree';
import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/util';
import * as util from '../util';
import { Scope } from 'ts-eslint';

export default util.createRule({
name: 'prefer-for-of',
Expand Down Expand Up @@ -159,7 +158,7 @@ export default util.createRule({

function isIndexOnlyUsedWithArray(
body: TSESTree.Statement,
indexVar: Scope.Variable,
indexVar: TSESLint.Scope.Variable,
arrayExpression: TSESTree.Expression,
): boolean {
const sourceCode = context.getSourceCode();
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/prefer-function-type.ts
@@ -1,8 +1,8 @@
import {
AST_NODE_TYPES,
TSESTree,
AST_TOKEN_TYPES,
} from '@typescript-eslint/typescript-estree';
TSESTree,
} from '@typescript-eslint/util';
import * as util from '../util';

export default util.createRule({
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/prefer-includes.ts
@@ -1,4 +1,4 @@
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { TSESTree } from '@typescript-eslint/util';
import { getStaticValue } from 'eslint-utils';
import { AST as RegExpAST, parseRegExpLiteral } from 'regexpp';
import ts from 'typescript';
Expand Down
5 changes: 2 additions & 3 deletions packages/eslint-plugin/src/rules/prefer-interface.ts
@@ -1,5 +1,4 @@
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { RuleFix } from 'ts-eslint';
import { TSESLint, TSESTree } from '@typescript-eslint/util';
import * as util from '../util';

export default util.createRule({
Expand Down Expand Up @@ -33,7 +32,7 @@ export default util.createRule({
messageId: 'interfaceOverType',
fix(fixer) {
const typeNode = node.typeParameters || node.id;
const fixes: RuleFix[] = [];
const fixes: TSESLint.RuleFix[] = [];

const firstToken = sourceCode.getFirstToken(node);
if (firstToken) {
Expand Down
5 changes: 1 addition & 4 deletions packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts
@@ -1,7 +1,4 @@
import {
AST_NODE_TYPES,
AST_TOKEN_TYPES,
} from '@typescript-eslint/typescript-estree';
import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '@typescript-eslint/util';
import * as util from '../util';

export default util.createRule({
Expand Down