Skip to content
Permalink
Browse files

feat: Move shared types into their own package (#425)

  • Loading branch information...
bradzacher committed May 10, 2019
1 parent 6eb97d4 commit a7a03ce39f82fac47e9ef1ef052ee1366eeb8c8a
Showing with 1,729 additions and 1,313 deletions.
  1. +0 −1 .eslintignore
  2. +1 −0 .eslintrc.json
  3. +1 −1 packages/eslint-plugin/package.json
  4. +4 −1 packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts
  5. +1 −1 packages/eslint-plugin/src/rules/array-type.ts
  6. +4 −4 packages/eslint-plugin/src/rules/await-thenable.ts
  7. +6 −3 packages/eslint-plugin/src/rules/ban-types.ts
  8. +4 −1 packages/eslint-plugin/src/rules/camelcase.ts
  9. +4 −1 packages/eslint-plugin/src/rules/class-name-casing.ts
  10. +4 −3 packages/eslint-plugin/src/rules/explicit-function-return-type.ts
  11. +4 −1 packages/eslint-plugin/src/rules/explicit-member-accessibility.ts
  12. +1 −1 packages/eslint-plugin/src/rules/func-call-spacing.ts
  13. +2 −2 packages/eslint-plugin/src/rules/indent-new-do-not-use/BinarySearchTree.ts
  14. +2 −2 packages/eslint-plugin/src/rules/indent-new-do-not-use/OffsetStorage.ts
  15. +3 −4 packages/eslint-plugin/src/rules/indent-new-do-not-use/TokenInfo.ts
  16. +6 −6 packages/eslint-plugin/src/rules/indent-new-do-not-use/index.ts
  17. +4 −1 packages/eslint-plugin/src/rules/indent.ts
  18. +4 −1 packages/eslint-plugin/src/rules/member-delimiter-style.ts
  19. +1 −1 packages/eslint-plugin/src/rules/member-naming.ts
  20. +4 −1 packages/eslint-plugin/src/rules/member-ordering.ts
  21. +4 −1 packages/eslint-plugin/src/rules/no-array-constructor.ts
  22. +6 −3 packages/eslint-plugin/src/rules/no-extra-parens.ts
  23. +4 −1 packages/eslint-plugin/src/rules/no-extraneous-class.ts
  24. +4 −1 packages/eslint-plugin/src/rules/no-inferrable-types.ts
  25. +4 −1 packages/eslint-plugin/src/rules/no-magic-numbers.ts
  26. +4 −1 packages/eslint-plugin/src/rules/no-misused-new.ts
  27. +4 −1 packages/eslint-plugin/src/rules/no-namespace.ts
  28. +4 −1 packages/eslint-plugin/src/rules/no-object-literal-type-assertion.ts
  29. +4 −1 packages/eslint-plugin/src/rules/no-parameter-properties.ts
  30. +1 −1 packages/eslint-plugin/src/rules/no-require-imports.ts
  31. +4 −1 packages/eslint-plugin/src/rules/no-this-alias.ts
  32. +6 −3 packages/eslint-plugin/src/rules/no-type-alias.ts
  33. +1 −1 packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts
  34. +1 −1 packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts
  35. +4 −1 packages/eslint-plugin/src/rules/no-unused-vars.ts
  36. +16 −13 packages/eslint-plugin/src/rules/no-use-before-define.ts
  37. +4 −1 packages/eslint-plugin/src/rules/no-useless-constructor.ts
  38. +1 −1 packages/eslint-plugin/src/rules/no-var-requires.ts
  39. +6 −3 packages/eslint-plugin/src/rules/prefer-for-of.ts
  40. +2 −2 packages/eslint-plugin/src/rules/prefer-function-type.ts
  41. +1 −1 packages/eslint-plugin/src/rules/prefer-includes.ts
  42. +2 −3 packages/eslint-plugin/src/rules/prefer-interface.ts
  43. +1 −1 packages/eslint-plugin/src/rules/prefer-namespace-keyword.ts
  44. +5 −6 packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts
  45. +1 −1 packages/eslint-plugin/src/rules/promise-function-async.ts
  46. +2 −2 packages/eslint-plugin/src/rules/require-array-sort-compare.ts
  47. +1 −1 packages/eslint-plugin/src/rules/restrict-plus-operands.ts
  48. +7 −4 packages/eslint-plugin/src/rules/semi.ts
  49. +1 −1 packages/eslint-plugin/src/rules/type-annotation-spacing.ts
  50. +5 −3 packages/eslint-plugin/src/rules/unbound-method.ts
  51. +4 −1 packages/eslint-plugin/src/rules/unified-signatures.ts
  52. +5 −58 packages/eslint-plugin/src/util/createRule.ts
  53. +4 −2 packages/eslint-plugin/src/util/getParserServices.ts
  54. +6 −2 packages/eslint-plugin/src/util/index.ts
  55. +9 −7 packages/eslint-plugin/src/util/misc.ts
  56. +4 −122 packages/eslint-plugin/tests/RuleTester.ts
  57. +1 −1 packages/eslint-plugin/tests/eslint-rules/no-redeclare.test.ts
  58. +9 −8 packages/eslint-plugin/tests/rules/func-call-spacing.test.ts
  59. +1 −1 packages/eslint-plugin/tests/rules/indent/indent-eslint.test.ts
  60. +6 −4 packages/eslint-plugin/tests/rules/indent/indent.test.ts
  61. +5 −5 packages/eslint-plugin/tests/rules/indent/utils.ts
  62. +1 −1 packages/eslint-plugin/tests/rules/no-array-constructor.test.ts
  63. +1 −1 packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts
  64. +1 −1 packages/eslint-plugin/tests/rules/no-for-in-array.test.ts
  65. +6 −2 packages/eslint-plugin/tests/rules/no-inferrable-types.test.ts
  66. +1 −1 packages/eslint-plugin/tests/rules/no-this-alias.test.ts
  67. +1 −1 packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts
  68. +1 −1 packages/eslint-plugin/tests/rules/no-use-before-define.test.ts
  69. +1 −1 packages/eslint-plugin/tests/rules/prefer-function-type.test.ts
  70. +4 −3 packages/eslint-plugin/tests/rules/semi.test.ts
  71. +4 −3 packages/eslint-plugin/tests/rules/type-annotation-spacing.test.ts
  72. +0 −112 packages/eslint-plugin/tests/util.test.ts
  73. +34 −51 packages/eslint-plugin/typings/eslint-rules.d.ts
  74. +12 −13 packages/eslint-plugin/typings/eslint-utils.d.ts
  75. +0 −716 packages/eslint-plugin/typings/ts-eslint.d.ts
  76. +21 −0 packages/experimental-utils/LICENSE
  77. +33 −0 packages/experimental-utils/README.md
  78. +13 −0 packages/experimental-utils/jest.config.js
  79. +40 −0 packages/experimental-utils/package.json
  80. +65 −0 packages/experimental-utils/src/eslint-utils/RuleCreator.ts
  81. 0 packages/{eslint-plugin/src/util → experimental-utils/src/eslint-utils}/applyDefault.ts
  82. +59 −0 packages/experimental-utils/src/eslint-utils/batchedSingleLineTests.ts
  83. 0 packages/{eslint-plugin/src/util → experimental-utils/src/eslint-utils}/deepMerge.ts
  84. +4 −0 packages/experimental-utils/src/eslint-utils/index.ts
  85. +13 −0 packages/experimental-utils/src/index.ts
  86. +18 −0 packages/experimental-utils/src/ts-eslint/AST.ts
  87. +132 −0 packages/experimental-utils/src/ts-eslint/Linter.ts
  88. +21 −0 packages/experimental-utils/src/ts-eslint/ParserOptions.ts
  89. +400 −0 packages/experimental-utils/src/ts-eslint/Rule.ts
  90. +76 −0 packages/experimental-utils/src/ts-eslint/RuleTester.ts
  91. +106 −0 packages/experimental-utils/src/ts-eslint/Scope.ts
  92. +193 −0 packages/experimental-utils/src/ts-eslint/SourceCode.ts
  93. +7 −0 packages/experimental-utils/src/ts-eslint/index.ts
  94. +58 −0 packages/experimental-utils/tests/eslint-utils/applyDefault.test.ts
  95. +60 −0 packages/experimental-utils/tests/eslint-utils/deepMerge.test.ts
  96. +9 −0 packages/experimental-utils/tsconfig.build.json
  97. +8 −0 packages/experimental-utils/tsconfig.json
  98. +1 −1 packages/parser/package.json
  99. +7 −6 packages/parser/src/analyze-scope.ts
  100. +6 −4 packages/parser/src/parser.ts
  101. +1 −2 packages/parser/src/scope/scope-manager.ts
  102. +1 −1 packages/parser/src/scope/scopes.ts
  103. +4 −2 packages/parser/tests/lib/parser.ts
  104. +8 −8 packages/parser/typings/eslint-scope.d.ts
  105. +2 −2 packages/typescript-estree/src/ast-converter.ts
  106. +1 −1 packages/typescript-estree/src/convert-comments.ts
  107. +2 −3 packages/typescript-estree/src/convert.ts
  108. +1 −1 packages/typescript-estree/src/node-utils.ts
  109. +8 −7 packages/typescript-estree/src/parser-options.ts
  110. +17 −17 packages/typescript-estree/src/parser.ts
  111. +1 −1 packages/typescript-estree/src/semantic-errors.ts
  112. +2 −2 packages/typescript-estree/src/ts-estree/index.ts
  113. +1 −1 packages/typescript-estree/src/ts-estree/ts-estree.ts
  114. +1 −1 packages/typescript-estree/src/{ → ts-estree}/ts-nodes.ts
  115. +1 −1 packages/typescript-estree/src/tsconfig-parser.ts
  116. +1 −1 packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
  117. +1 −1 packages/typescript-estree/tests/ast-alignment/parse.ts
  118. +1 −1 packages/typescript-estree/tests/ast-alignment/utils.ts
  119. +2 −2 packages/typescript-estree/tests/lib/comments.ts
  120. +2 −2 packages/typescript-estree/tests/lib/javascript.ts
  121. +2 −2 packages/typescript-estree/tests/lib/jsx.ts
  122. +5 −5 packages/typescript-estree/tests/lib/parse.ts
  123. +1 −1 packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts
  124. +7 −10 packages/typescript-estree/tests/lib/semanticInfo.ts
  125. +2 −2 packages/typescript-estree/tests/lib/tsx.ts
  126. +2 −2 packages/typescript-estree/tests/lib/typescript.ts
  127. +4 −4 packages/typescript-estree/tools/test-utils.ts
  128. +2 −1 packages/typescript-estree/tsconfig.build.json
  129. +4 −1 packages/typescript-estree/tsconfig.json
  130. +1 −1 yarn.lock
@@ -5,5 +5,4 @@ fixtures
shared-fixtures
coverage

packages/typescript-estree/src/estree
packages/eslint-plugin-tslint/tests
@@ -12,6 +12,7 @@
"no-dupe-class-members": "off",
"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",
@@ -37,7 +37,7 @@
},
"dependencies": {
"@typescript-eslint/parser": "1.7.0",
"@typescript-eslint/typescript-estree": "1.7.0",
"@typescript-eslint/experimental-utils": "1.7.0",
"eslint-utils": "^1.3.1",
"regexpp": "^2.0.1",
"requireindex": "^1.2.0",
@@ -1,4 +1,7 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import {
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

type RuleNode =
@@ -2,7 +2,7 @@ import {
AST_NODE_TYPES,
AST_TOKEN_TYPES,
TSESTree,
} from '@typescript-eslint/typescript-estree';
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

/**
@@ -1,5 +1,5 @@
import * as tsutils from 'tsutils';
import * as ts from 'typescript';
import ts from 'typescript';

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

@@ -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);
const type = checker.getTypeAtLocation(originalNode.expression);

if (
@@ -1,5 +1,8 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { ReportFixFunction } from 'ts-eslint';
import {
TSESLint,
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

type Options = [
@@ -94,7 +97,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}`;
@@ -1,4 +1,7 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import {
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import baseRule from 'eslint/lib/rules/camelcase';
import * as util from '../util';

@@ -1,5 +1,8 @@
import {
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';

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

type Options = [
{
allowExpressions?: boolean;
allowTypedFunctionExpressions?: boolean;
allowUntypedSetters?: boolean;
}
];
type MessageIds = 'missingReturnType';
@@ -42,7 +44,6 @@ export default util.createRule<Options, MessageIds>({
{
allowExpressions: false,
allowTypedFunctionExpressions: false,
allowUntypedSetters: true,
},
],
create(context, [options]) {
@@ -1,4 +1,7 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import {
AST_NODE_TYPES,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

type AccessibilityLevel =
@@ -1,4 +1,4 @@
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { TSESTree } from '@typescript-eslint/experimental-utils';
import { isOpeningParenToken } from 'eslint-utils';
import * as util from '../util';

@@ -1,8 +1,8 @@
// The following code is adapted from the the code in eslint.
// License: https://github.com/eslint/eslint/blob/48700fc8408f394887cdedd071b22b757700fdcb/LICENSE

import { TSESTree } from '@typescript-eslint/typescript-estree';
import createTree = require('functional-red-black-tree');
import { TSESTree } from '@typescript-eslint/experimental-utils';
import createTree from 'functional-red-black-tree';

export type TokenOrComment = TSESTree.Token | TSESTree.Comment;
export interface TreeValue {
@@ -1,9 +1,9 @@
// The following code is adapted from the the code in eslint.
// License: https://github.com/eslint/eslint/blob/48700fc8408f394887cdedd071b22b757700fdcb/LICENSE

import { TokenInfo } from './TokenInfo';
import { TSESTree } from '@typescript-eslint/experimental-utils';
import { BinarySearchTree, TokenOrComment } from './BinarySearchTree';
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { TokenInfo } from './TokenInfo';

/**
* A class to store information on desired offsets of tokens from each other
@@ -1,18 +1,17 @@
// The following code is adapted from the the code in eslint.
// License: https://github.com/eslint/eslint/blob/48700fc8408f394887cdedd071b22b757700fdcb/LICENSE

import { TSESTree } from '@typescript-eslint/typescript-estree';
import { SourceCode } from 'ts-eslint';
import { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';
import { TokenOrComment } from './BinarySearchTree';

/**
* A helper class to get token-based info related to indentation
*/
export class TokenInfo {
private sourceCode: SourceCode;
private sourceCode: TSESLint.SourceCode;
public firstTokensByLineNumber: Map<number, TSESTree.Token>;

constructor(sourceCode: SourceCode) {
constructor(sourceCode: TSESLint.SourceCode) {
this.sourceCode = sourceCode;
this.firstTokensByLineNumber = sourceCode.tokensAndComments.reduce(
(map, token) => {
@@ -6,7 +6,8 @@ import {
AST_NODE_TYPES,
TSESTree,
AST_TOKEN_TYPES,
} from '@typescript-eslint/typescript-estree';
TSESLint,
} from '@typescript-eslint/experimental-utils';
import { createGlobalLinebreakMatcher } from 'eslint/lib/util/ast-utils';
import {
isOpeningParenToken,
@@ -20,7 +21,6 @@ import {
isColonToken,
isCommentToken,
} from 'eslint-utils';
import { RuleListener, RuleFunction } from 'ts-eslint';
import { TokenOrComment } from './BinarySearchTree';
import { OffsetStorage } from './OffsetStorage';
import { TokenInfo } from './TokenInfo';
@@ -848,7 +848,7 @@ export default createRule<Options, MessageIds>({

const ignoredNodeFirstTokens = new Set();

const baseOffsetListeners: RuleListener = {
const baseOffsetListeners: TSESLint.RuleListener = {
'ArrayExpression, ArrayPattern'(
node: TSESTree.ArrayExpression | TSESTree.ArrayPattern,
) {
@@ -1547,7 +1547,7 @@ export default createRule<Options, MessageIds>({
};

const listenerCallQueue: {
listener: RuleFunction<TSESTree.Node>;
listener: TSESLint.RuleFunction<TSESTree.Node>;
node: TSESTree.Node;
}[] = [];

@@ -1558,7 +1558,7 @@ export default createRule<Options, MessageIds>({
* 3. Call `ignoreNode` on the node sometime after exiting it and before validating offsets.
*/
const offsetListeners = Object.keys(baseOffsetListeners).reduce<
RuleListener
TSESLint.RuleListener
>(
/*
* Offset listener calls are deferred until traversal is finished, and are called as
@@ -1577,7 +1577,7 @@ export default createRule<Options, MessageIds>({
* ignored nodes are known.
*/
(acc, key) => {
const listener = baseOffsetListeners[key] as RuleFunction<
const listener = baseOffsetListeners[key] as TSESLint.RuleFunction<
TSESTree.Node
>;
acc[key] = node => listenerCallQueue.push({ listener, node });
@@ -4,7 +4,10 @@
* 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/experimental-utils';
import baseRule from 'eslint/lib/rules/indent';
import * as util from '../util';

@@ -1,4 +1,7 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import {
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

type Delimiter = 'comma' | 'none' | 'semi';
@@ -1,4 +1,4 @@
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { TSESTree } from '@typescript-eslint/experimental-utils';
import * as util from '../util';

interface Config<T = string> {
@@ -1,4 +1,7 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import {
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

type MessageIds = 'incorrectOrder';
@@ -1,4 +1,7 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import {
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

export default util.createRule({
@@ -1,5 +1,8 @@
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree';
import { RuleListener } from 'ts-eslint';
import {
AST_NODE_TYPES,
TSESTree,
TSESLint,
} from '@typescript-eslint/experimental-utils';
import baseRule from 'eslint/lib/rules/no-extra-parens';
import * as util from '../util';

@@ -85,7 +88,7 @@ export default util.createRule<Options, MessageIds>({
return rule(node);
}

const overrides: RuleListener = {
const overrides: TSESLint.RuleListener = {
// ArrayExpression
ArrowFunctionExpression(node) {
if (node.body.type !== AST_NODE_TYPES.TSAsExpression) {
@@ -1,4 +1,7 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import {
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

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

type Options = [
@@ -3,7 +3,10 @@
* @author Scott O'Hara
*/

import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import {
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import baseRule from 'eslint/lib/rules/no-magic-numbers';
import * as util from '../util';
import { JSONSchema4 } from 'json-schema';
@@ -1,4 +1,7 @@
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import {
TSESTree,
AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

export default util.createRule({
@@ -1,4 +1,7 @@
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree';
import {
AST_NODE_TYPES,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

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

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

type Modifier =
@@ -1,4 +1,4 @@
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { TSESTree } from '@typescript-eslint/experimental-utils';
import * as util from '../util';

export default util.createRule({
@@ -1,4 +1,7 @@
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/typescript-estree';
import {
AST_NODE_TYPES,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import * as util from '../util';

type Options = [
Oops, something went wrong.

0 comments on commit a7a03ce

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