Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry committed Aug 19, 2019
2 parents 8d70bda + 9f82099 commit 4164a2b
Show file tree
Hide file tree
Showing 16 changed files with 924 additions and 9 deletions.
37 changes: 37 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: catch-all template
about: Provides some general structure to issues that people choose to log outside the normal flow
title: ''
labels: triage
assignees: ''
---

**What were you trying to do?**

```json
{
"rules": {
"@typescript-eslint/<rule>": ["<setting>"]
}
}
```

```ts
// Put your code here
```

**What did you expect to happen?**

**What actually happened?**

**Versions**

| package | version |
| --------------------------------------- | ------- |
| `@typescript-eslint/eslint-plugin` | `X.Y.Z` |
| `@typescript-eslint/parser` | `X.Y.Z` |
| `@typescript-eslint/typescript-estree` | `X.Y.Z` |
| `@typescript-eslint/experimental-utils` | `X.Y.Z` |
| `TypeScript` | `X.Y.Z` |
| `node` | `X.Y.Z` |
| `npm` | `X.Y.Z` |
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/eslint-plugin-typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Are you opening an issue because the rule you're trying to use is not found?
1) Check the releases log: https://github.com/typescript-eslint/typescript-eslint/releases
- If the rule isn't listed there, then chances are it hasn't been released to the main npm tag yet.
2) Try installing the `canary` tag: `npm i @typescript-eslint/eslint-plugin@canary`.
- The canary tag is built for every commit to master, so it contains the bleeding edge build.
- The canary tag is built for every commit to master, so it contains the bleeding edge build.
3) If ESLint still can't find the rule, then consider reporting an issue.
-->

Expand Down
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/typescript-eslint-utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: '@typescript-eslint/experimental-utils'
about: Report an issue with the `@typescript-eslint/experimental-utils` package
title: ''
labels: 'package: utils, triage'
assignees: ''
---

**What did you expect to happen?**

**What actually happened?**

**Versions**

| package | version |
| --------------------------------------- | ------- |
| `@typescript-eslint/experimental-utils` | `X.Y.Z` |
| `TypeScript` | `X.Y.Z` |
| `node` | `X.Y.Z` |
| `npm` | `X.Y.Z` |
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ jspm_packages/
.DS_Store
.idea
dist

# Editor-specific metadata folders
.vs
1 change: 1 addition & 0 deletions packages/eslint-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e
| [`@typescript-eslint/prefer-regexp-exec`](./docs/rules/prefer-regexp-exec.md) | Prefer RegExp#exec() over String#match() if no global flag is provided | :heavy_check_mark: | | :thought_balloon: |
| [`@typescript-eslint/prefer-string-starts-ends-with`](./docs/rules/prefer-string-starts-ends-with.md) | Enforce the use of `String#startsWith` and `String#endsWith` instead of other equivalent methods of checking substrings | :heavy_check_mark: | :wrench: | :thought_balloon: |
| [`@typescript-eslint/promise-function-async`](./docs/rules/promise-function-async.md) | Requires any function or method that returns a Promise to be marked async | | | :thought_balloon: |
| [`@typescript-eslint/quotes`](./docs/rules/quotes.md) | Enforce the consistent use of either backticks, double, or single quotes | | :wrench: | |
| [`@typescript-eslint/require-array-sort-compare`](./docs/rules/require-array-sort-compare.md) | Enforce giving `compare` argument to `Array#sort` | | | :thought_balloon: |
| [`@typescript-eslint/require-await`](./docs/rules/require-await.md) | Disallow async functions which have no `await` expression | :heavy_check_mark: | | :thought_balloon: |
| [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string | | | :thought_balloon: |
Expand Down
22 changes: 22 additions & 0 deletions packages/eslint-plugin/docs/rules/quotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Enforce the consistent use of either backticks, double, or single quotes

## Rule Details

This rule extends the base [eslint/quotes](https://eslint.org/docs/rules/quotes) rule.
It supports all options and features of the base rule.

## How to use

```cjson
{
// note you must disable the base rule as it can report incorrect errors
"quotes": "off",
"@typescript-eslint/quotes": ["error"]
}
```

## Options

See [eslint/quotes options](https://eslint.org/docs/rules/quotes#options).

<sup>Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/quotes.md)</sup>
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"typescript": "*"
},
"peerDependencies": {
"@typescript-eslint/parser": "^2.0.0-alpha.0",
"@typescript-eslint/parser": "^2.0.0",
"eslint": "^5.0.0 || ^6.0.0"
}
}
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/configs/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"@typescript-eslint/prefer-regexp-exec": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"quotes": "off",
"@typescript-eslint/quotes": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"require-await": "off",
"@typescript-eslint/require-await": "error",
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import preferReadonly from './prefer-readonly';
import preferRegexpExec from './prefer-regexp-exec';
import preferStringStartsEndsWith from './prefer-string-starts-ends-with';
import promiseFunctionAsync from './promise-function-async';
import quotes from './quotes';
import requireArraySortCompare from './require-array-sort-compare';
import requireAwait from './require-await';
import restrictPlusOperands from './restrict-plus-operands';
Expand Down Expand Up @@ -112,6 +113,7 @@ export default {
'prefer-regexp-exec': preferRegexpExec,
'prefer-string-starts-ends-with': preferStringStartsEndsWith,
'promise-function-async': promiseFunctionAsync,
quotes: quotes,
'require-array-sort-compare': requireArraySortCompare,
'require-await': requireAwait,
'restrict-plus-operands': restrictPlusOperands,
Expand Down
62 changes: 62 additions & 0 deletions packages/eslint-plugin/src/rules/quotes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
AST_NODE_TYPES,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import baseRule from 'eslint/lib/rules/quotes';
import * as util from '../util';

export type Options = util.InferOptionsTypeFromRule<typeof baseRule>;
export type MessageIds = util.InferMessageIdsTypeFromRule<typeof baseRule>;

export default util.createRule<Options, MessageIds>({
name: 'quotes',
meta: {
type: 'layout',
docs: {
description:
'Enforce the consistent use of either backticks, double, or single quotes',
category: 'Stylistic Issues',
recommended: false,
},
fixable: 'code',
messages: baseRule.meta.messages,
schema: baseRule.meta.schema,
},
defaultOptions: [
'double',
{
allowTemplateLiterals: false,
avoidEscape: false,
},
],
create(context, [option]) {
const rules = baseRule.create(context);

const isModuleDeclaration = (node: TSESTree.Literal): boolean => {
return (
!!node.parent && node.parent.type === AST_NODE_TYPES.TSModuleDeclaration
);
};

const isTypeLiteral = (node: TSESTree.Literal): boolean => {
return !!node.parent && node.parent.type === AST_NODE_TYPES.TSLiteralType;
};

return {
Literal(node) {
if (
option === 'backtick' &&
(isModuleDeclaration(node) || isTypeLiteral(node))
) {
return;
}

rules.Literal(node);
},

TemplateLiteral(node) {
rules.TemplateLiteral(node);
},
};
},
});
38 changes: 31 additions & 7 deletions packages/eslint-plugin/src/rules/unified-signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type ScopeNode =
| TSESTree.TSTypeLiteral;

type OverloadNode = MethodDefinition | SignatureDefinition;
type ContainingNode =
| TSESTree.ExportNamedDeclaration
| TSESTree.ExportDefaultDeclaration;

type SignatureDefinition =
| TSESTree.FunctionExpression
Expand Down Expand Up @@ -424,7 +427,8 @@ export default util.createRule({
a === b ||
(a !== undefined &&
b !== undefined &&
a.typeAnnotation.type === b.typeAnnotation.type)
sourceCode.getText(a.typeAnnotation) ===
sourceCode.getText(b.typeAnnotation))
);
}

Expand Down Expand Up @@ -495,9 +499,16 @@ export default util.createRule({
currentScope = scopes.pop()!;
}

function addOverload(signature: OverloadNode, key?: string): void {
function addOverload(
signature: OverloadNode,
key?: string,
containingNode?: ContainingNode,
): void {
key = key || getOverloadKey(signature);
if (currentScope && signature.parent === currentScope.parent && key) {
if (
currentScope &&
(containingNode || signature).parent === currentScope.parent
) {
const overloads = currentScope.overloads.get(key);
if (overloads !== undefined) {
overloads.push(signature);
Expand All @@ -521,11 +532,10 @@ export default util.createRule({
createScope(node.body, node.typeParameters);
},
TSTypeLiteral: createScope,

// collect overloads
TSDeclareFunction(node): void {
if (node.id && !node.body) {
addOverload(node, node.id.name);
}
addOverload(node, node.id.name, getExportingNode(node));
},
TSCallSignatureDeclaration: addOverload,
TSConstructSignatureDeclaration: addOverload,
Expand All @@ -540,6 +550,7 @@ export default util.createRule({
addOverload(node);
}
},

// validate scopes
'Program:exit': checkScope,
'TSModuleBlock:exit': checkScope,
Expand All @@ -550,7 +561,20 @@ export default util.createRule({
},
});

function getOverloadKey(node: OverloadNode): string | undefined {
function getExportingNode(
node: TSESTree.TSDeclareFunction,
):
| TSESTree.ExportNamedDeclaration
| TSESTree.ExportDefaultDeclaration
| undefined {
return node.parent &&
(node.parent.type === AST_NODE_TYPES.ExportNamedDeclaration ||
node.parent.type === AST_NODE_TYPES.ExportDefaultDeclaration)
? node.parent
: undefined;
}

function getOverloadKey(node: OverloadNode): string {
const info = getOverloadInfo(node);

return (
Expand Down

0 comments on commit 4164a2b

Please sign in to comment.