From cf1cba32a1b8fd85886124695cabd3ed4ffea9b8 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 23 Sep 2019 09:37:12 -0700 Subject: [PATCH 1/6] fix: allow tsx testing --- .gitignore | 1 + packages/eslint-plugin/package.json | 1 + packages/eslint-plugin/tests/RuleTester.ts | 39 ++++++++++-------- .../eslint-plugin/tests/fixtures/react.tsx | 0 .../tests/fixtures/tsconfig.json | 7 +++- .../no-unnecessary-type-assertion.test.ts | 40 +++++++++++++++++++ packages/parser/src/parser.ts | 1 + .../typescript-estree/src/convert-comments.ts | 39 ++++++++++-------- packages/typescript-estree/src/node-utils.ts | 4 +- packages/typescript-estree/src/parser.ts | 1 + .../typescript-estree/src/tsconfig-parser.ts | 4 +- yarn.lock | 18 +++++++++ 12 files changed, 117 insertions(+), 38 deletions(-) create mode 100644 packages/eslint-plugin/tests/fixtures/react.tsx diff --git a/.gitignore b/.gitignore index 3a06baccf6f5..1b19ec575235 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,4 @@ dist # Editor-specific metadata folders .vs +.watchmanconfig diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index ee8d22ae84ef..e86e8158fecb 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -50,6 +50,7 @@ "@types/json-schema": "^7.0.3", "@types/marked": "^0.6.5", "@types/prettier": "^1.18.2", + "@types/react": "^16.9.2", "chalk": "^2.4.2", "marked": "^0.7.0", "prettier": "*", diff --git a/packages/eslint-plugin/tests/RuleTester.ts b/packages/eslint-plugin/tests/RuleTester.ts index 978adc109669..4d2045090780 100644 --- a/packages/eslint-plugin/tests/RuleTester.ts +++ b/packages/eslint-plugin/tests/RuleTester.ts @@ -1,4 +1,5 @@ import { TSESLint, ESLintUtils } from '@typescript-eslint/experimental-utils'; +import { clearCaches } from '@typescript-eslint/parser'; import * as path from 'path'; const parser = '@typescript-eslint/parser'; @@ -33,35 +34,33 @@ class RuleTester extends TSESLint.RuleTester { ): void { const errorMessage = `Do not set the parser at the test level unless you want to use a parser other than ${parser}`; - if (this.filename) { - tests.valid = tests.valid.map(test => { - if (typeof test === 'string') { - return { - code: test, - filename: this.filename, - }; - } - return test; - }); - } + // standardise the valid tests as objects + tests.valid = tests.valid.map(test => { + if (typeof test === 'string') { + return { + code: test, + }; + } + return test; + }); tests.valid.forEach(test => { if (typeof test !== 'string') { if (test.parser === parser) { throw new Error(errorMessage); } - if (!test.filename) { - test.filename = this.filename; - } + test.filename = test.filename + ? path.join(getFixturesRootDir(), test.filename) + : this.filename; } }); tests.invalid.forEach(test => { if (test.parser === parser) { throw new Error(errorMessage); } - if (!test.filename) { - test.filename = this.filename; - } + test.filename = test.filename + ? path.join(getFixturesRootDir(), test.filename) + : this.filename; }); super.run(name, rule, tests); @@ -74,4 +73,10 @@ function getFixturesRootDir(): string { const { batchedSingleLineTests } = ESLintUtils; +// make sure each test is completely isolated +// otherwise the stored state may impact other tests +afterEach(() => { + clearCaches(); +}); + export { RuleTester, getFixturesRootDir, batchedSingleLineTests }; diff --git a/packages/eslint-plugin/tests/fixtures/react.tsx b/packages/eslint-plugin/tests/fixtures/react.tsx new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/eslint-plugin/tests/fixtures/tsconfig.json b/packages/eslint-plugin/tests/fixtures/tsconfig.json index bedda0e3decc..25bdbb025661 100644 --- a/packages/eslint-plugin/tests/fixtures/tsconfig.json +++ b/packages/eslint-plugin/tests/fixtures/tsconfig.json @@ -1,9 +1,14 @@ { "compilerOptions": { + "jsx": "preserve", "target": "es5", "module": "commonjs", "strict": true, "esModuleInterop": true, "lib": ["es2015", "es2017", "esnext"] - } + }, + "include": [ + "file.ts", + "react.tsx" + ] } diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts index 4b4e496253f5..2f151a8ad935 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts @@ -104,6 +104,46 @@ class Mx { private prop = 1; } `, + // https://github.com/typescript-eslint/typescript-eslint/issues/982 + { + code: ` +const React = require("react"); + +function Test(props: { + id?: null | string | number; +}) { + return
; +}; + `, + filename: 'react.tsx', + }, + { + code: ` +const React = require("react"); + +export namespace appTest { + type ArtificialKey = string | number; + interface ReactAttributeArtificial { + key?: ArtificialKey; + } + type Data = { + id?: null | string | number; + }; + + export const Test = (props: Data) => { + return ChildFn({ key: props.id! }); + }; + + export const Test2 = (props: Data) => { + return ; + }; + + const ChildFn = (props: ReactAttributeArtificial) => "Hello"; + const ChildCmp = () =>
Hello
; +} + `, + filename: 'react.tsx', + }, ], invalid: [ diff --git a/packages/parser/src/parser.ts b/packages/parser/src/parser.ts index 830a282da1e4..bcb6dde759a4 100644 --- a/packages/parser/src/parser.ts +++ b/packages/parser/src/parser.ts @@ -115,3 +115,4 @@ export function parseForESLint( } export { ParserServices, ParserOptions }; +export { clearCaches } from '@typescript-eslint/typescript-estree'; diff --git a/packages/typescript-estree/src/convert-comments.ts b/packages/typescript-estree/src/convert-comments.ts index d3738774cd90..ea582495adf7 100644 --- a/packages/typescript-estree/src/convert-comments.ts +++ b/packages/typescript-estree/src/convert-comments.ts @@ -118,24 +118,26 @@ export function convertComments( case ts.SyntaxKind.GreaterThanToken: container = getNodeContainer(ast, start, end); if ( - (container.parent && + container && + ((container.parent && container.parent.parent && // Rescan after an opening element or fragment (container.parent.kind === ts.SyntaxKind.JsxOpeningElement && // Make sure this is the end of a tag like `>` container.parent.end === end)) || - container.parent.kind === ts.SyntaxKind.JsxOpeningFragment || - // Rescan after a self-closing element if it's inside another JSX element - (container.parent.kind === ts.SyntaxKind.JsxSelfClosingElement && - (container.parent.parent.kind === ts.SyntaxKind.JsxElement || - container.parent.parent.kind === ts.SyntaxKind.JsxFragment)) || - // Rescan after a closing element if it's inside another JSX element - ((container.parent.kind === ts.SyntaxKind.JsxClosingElement || - container.parent.kind === ts.SyntaxKind.JsxClosingFragment) && - container.parent.parent.parent && - (container.parent.parent.parent.kind === ts.SyntaxKind.JsxElement || - container.parent.parent.parent.kind === - ts.SyntaxKind.JsxFragment)) + container.parent.kind === ts.SyntaxKind.JsxOpeningFragment || + // Rescan after a self-closing element if it's inside another JSX element + (container.parent.kind === ts.SyntaxKind.JsxSelfClosingElement && + (container.parent.parent.kind === ts.SyntaxKind.JsxElement || + container.parent.parent.kind === ts.SyntaxKind.JsxFragment)) || + // Rescan after a closing element if it's inside another JSX element + ((container.parent.kind === ts.SyntaxKind.JsxClosingElement || + container.parent.kind === ts.SyntaxKind.JsxClosingFragment) && + container.parent.parent.parent && + (container.parent.parent.parent.kind === + ts.SyntaxKind.JsxElement || + container.parent.parent.parent.kind === + ts.SyntaxKind.JsxFragment))) ) { kind = triviaScanner.reScanJsxToken(); continue; @@ -146,6 +148,7 @@ export function convertComments( // Rescan after a JSX expression if ( + container && container.parent && container.parent.kind === ts.SyntaxKind.JsxExpression && container.parent.parent && @@ -156,8 +159,9 @@ export function convertComments( } if ( - container.kind === ts.SyntaxKind.TemplateMiddle || - container.kind === ts.SyntaxKind.TemplateTail + container && + (container.kind === ts.SyntaxKind.TemplateMiddle || + container.kind === ts.SyntaxKind.TemplateTail) ) { kind = triviaScanner.reScanTemplateToken(); continue; @@ -167,7 +171,10 @@ export function convertComments( case ts.SyntaxKind.SlashEqualsToken: container = getNodeContainer(ast, start, end); - if (container.kind === ts.SyntaxKind.RegularExpressionLiteral) { + if ( + container && + container.kind === ts.SyntaxKind.RegularExpressionLiteral + ) { kind = triviaScanner.reScanSlashToken(); continue; } diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index c23daf6e3173..c51c57bbcdf3 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -621,7 +621,7 @@ export function getNodeContainer( ast: ts.SourceFile, start: number, end: number, -): ts.Node { +): ts.Node | null { let container: ts.Node | null = null; /** @@ -641,7 +641,7 @@ export function getNodeContainer( } walk(ast); - return container!; + return container; } export interface TSError { diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index 882a8bbff7e5..6a04d82f561e 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -499,4 +499,5 @@ export function parseAndGenerateServices< } export { TSESTreeOptions, ParserServices }; +export { clearCaches } from './tsconfig-parser'; export * from './ts-estree'; diff --git a/packages/typescript-estree/src/tsconfig-parser.ts b/packages/typescript-estree/src/tsconfig-parser.ts index e6ef356b6f30..9fe6a699310b 100644 --- a/packages/typescript-estree/src/tsconfig-parser.ts +++ b/packages/typescript-estree/src/tsconfig-parser.ts @@ -35,8 +35,8 @@ const watchCallbackTrackingMap = new Map(); const parsedFilesSeen = new Set(); /** - * Clear tsconfig caches. - * Primarily used for testing. + * Clear all of the parser caches. + * This should only be used in testing to ensure the parser is clean between tests. */ export function clearCaches(): void { knownWatchProgramMap.clear(); diff --git a/yarn.lock b/yarn.lock index 9f41d090fe99..d83ac73f6555 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1463,6 +1463,19 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-1.18.2.tgz#069e7d132024d436fd1f5771f6932426a695f230" integrity sha512-2JBasa5Qaj81Qsp/dxX2Njy+MdKC767WytHUDsRM7TYEfQvKPxsnGpnCBlBS1i2Aiv1YwCpmKSbQ6O6v8TpiKg== +"@types/prop-types@*": + version "15.7.2" + resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.2.tgz#0e58ae66773d7fd7c372a493aff740878ec9ceaa" + integrity sha512-f8JzJNWVhKtc9dg/dyDNfliTKNOJSLa7Oht/ElZdF/UbMUmAH3rLmAk3ODNjw0mZajDEgatA03tRjB4+Dp/tzA== + +"@types/react@^16.9.2": + version "16.9.2" + resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.2.tgz#6d1765431a1ad1877979013906731aae373de268" + integrity sha512-jYP2LWwlh+FTqGd9v7ynUKZzjj98T8x7Yclz479QdRhHfuW9yQ+0jjnD31eXSXutmBpppj5PYNLYLRfnZJvcfg== + dependencies: + "@types/prop-types" "*" + csstype "^2.2.0" + "@types/semver@^6.0.1": version "6.0.1" resolved "https://registry.yarnpkg.com/@types/semver/-/semver-6.0.1.tgz#a984b405c702fa5a7ec6abc56b37f2ba35ef5af6" @@ -3019,6 +3032,11 @@ cssstyle@^1.0.0: dependencies: cssom "0.3.x" +csstype@^2.2.0: + version "2.6.6" + resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.6.tgz#c34f8226a94bbb10c32cc0d714afdf942291fc41" + integrity sha512-RpFbQGUE74iyPgvr46U9t1xoQBM8T4BL8SxrN66Le2xYAPSaDJJKeztV3awugusb3g3G9iL8StmkBBXhcbbXhg== + currently-unhandled@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea" From df410a11963a19f052b13c2e1f6dadf429ae7bc2 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 23 Sep 2019 10:11:48 -0700 Subject: [PATCH 2/6] fix(eslint-plugin): handle jsx attributes --- .../rules/no-unnecessary-type-assertion.ts | 18 ++++-- .../no-unnecessary-type-assertion.test.ts | 55 ++++++++++--------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts index 61583878bae9..23c686fc7a68 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts @@ -1,6 +1,7 @@ import { TSESTree } from '@typescript-eslint/experimental-utils'; import { isCallExpression, + isJsxExpression, isNewExpression, isObjectType, isObjectFlagSet, @@ -117,6 +118,8 @@ export default util.createRule({ return parent.type ? checker.getTypeFromTypeNode(parent.type) : undefined; + } else if (isJsxExpression(parent)) { + return checker.getContextualType(parent); } else if ( ![ts.SyntaxKind.TemplateSpan, ts.SyntaxKind.JsxExpression].includes( parent.kind, @@ -216,10 +219,17 @@ export default util.createRule({ contextualType, ts.TypeFlags.Null, ); - if ( - (typeIncludesUndefined && contextualTypeIncludesUndefined) || - (typeIncludesNull && contextualTypeIncludesNull) - ) { + + // make sure that the parent accepts the same types + // i.e. assigning `string | null | undefined` to `string | undefined` is invalid + const isValidUndefined = typeIncludesUndefined + ? contextualTypeIncludesUndefined + : true; + const isValidNull = typeIncludesNull + ? contextualTypeIncludesNull + : true; + + if (isValidUndefined && isValidNull) { context.report({ node, messageId: 'contextuallyUnnecessary', diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts index 2f151a8ad935..48e6b06cf3db 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts @@ -117,33 +117,6 @@ function Test(props: { `, filename: 'react.tsx', }, - { - code: ` -const React = require("react"); - -export namespace appTest { - type ArtificialKey = string | number; - interface ReactAttributeArtificial { - key?: ArtificialKey; - } - type Data = { - id?: null | string | number; - }; - - export const Test = (props: Data) => { - return ChildFn({ key: props.id! }); - }; - - export const Test2 = (props: Data) => { - return ; - }; - - const ChildFn = (props: ReactAttributeArtificial) => "Hello"; - const ChildCmp = () =>
Hello
; -} - `, - filename: 'react.tsx', - }, ], invalid: [ @@ -354,5 +327,33 @@ class Mx { }, ], }, + // https://github.com/typescript-eslint/typescript-eslint/issues/982 + { + code: ` +const React = require("react"); + +function Test(props: { + id?: string | number; +}) { + return
; +}; + `, + output: ` +const React = require("react"); + +function Test(props: { + id?: string | number; +}) { + return
; +}; + `, + errors: [ + { + messageId: 'contextuallyUnnecessary', + line: 7, + }, + ], + filename: 'react.tsx', + }, ], }); From dae2acd99d1e3b1d9accf9b23177579a5b857485 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 7 Oct 2019 21:44:26 -0700 Subject: [PATCH 3/6] fix: unbreak tests --- packages/eslint-plugin/tests/RuleTester.ts | 7 ------- .../tests/rules/no-unnecessary-type-assertion.test.ts | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/eslint-plugin/tests/RuleTester.ts b/packages/eslint-plugin/tests/RuleTester.ts index 4d2045090780..fcc71ec8c106 100644 --- a/packages/eslint-plugin/tests/RuleTester.ts +++ b/packages/eslint-plugin/tests/RuleTester.ts @@ -1,5 +1,4 @@ import { TSESLint, ESLintUtils } from '@typescript-eslint/experimental-utils'; -import { clearCaches } from '@typescript-eslint/parser'; import * as path from 'path'; const parser = '@typescript-eslint/parser'; @@ -73,10 +72,4 @@ function getFixturesRootDir(): string { const { batchedSingleLineTests } = ESLintUtils; -// make sure each test is completely isolated -// otherwise the stored state may impact other tests -afterEach(() => { - clearCaches(); -}); - export { RuleTester, getFixturesRootDir, batchedSingleLineTests }; diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts index 48e6b06cf3db..6d714df8525c 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts @@ -1,3 +1,4 @@ +import { clearCaches } from '@typescript-eslint/parser'; import path from 'path'; import rule from '../../src/rules/no-unnecessary-type-assertion'; import { RuleTester } from '../RuleTester'; @@ -12,6 +13,12 @@ const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', }); +// make sure each test is completely isolated +// there was some weird behaviour with the mixed ts/tsx test cases without this +afterEach(() => { + clearCaches(); +}); + ruleTester.run('no-unnecessary-type-assertion', rule, { valid: [ 'const foo = 3 as number;', From 8997b93f1a56b724a4b6671602bffcf6fee10044 Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 12 Jan 2020 00:01:16 +0100 Subject: [PATCH 4/6] test(eslint-plugin): update filename from relative to absolute path this should be fixed when #1424 gets merged --- .../tests/rules/no-unnecessary-type-assertion.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts index 540a26655c2b..84c5b22f15c7 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts @@ -135,7 +135,7 @@ function Test(props: { return
; }; `, - filename: 'react.tsx', + filename: path.join(rootDir, 'react.tsx'), }, ], @@ -373,7 +373,7 @@ function Test(props: { line: 7, }, ], - filename: 'react.tsx', + filename: path.join(rootDir, 'react.tsx'), }, ], }); From 553e1c9a6f74b1354758ca691cd076cabe9bbd8d Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 12 Jan 2020 00:10:46 +0100 Subject: [PATCH 5/6] chore(eslint-plugin): correct spelling issues --- packages/eslint-plugin/tests/RuleTester.ts | 2 +- .../tests/rules/no-unnecessary-type-assertion.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/tests/RuleTester.ts b/packages/eslint-plugin/tests/RuleTester.ts index 16f2f27fe2f4..c650c83449c4 100644 --- a/packages/eslint-plugin/tests/RuleTester.ts +++ b/packages/eslint-plugin/tests/RuleTester.ts @@ -44,7 +44,7 @@ class RuleTester extends TSESLint.RuleTester { ): void { const errorMessage = `Do not set the parser at the test level unless you want to use a parser other than ${parser}`; - // standardise the valid tests as objects + // standardize the valid tests as objects tests.valid = tests.valid.map(test => { if (typeof test === 'string') { return { diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts index 84c5b22f15c7..6cbf1baf2d39 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts @@ -14,7 +14,7 @@ const ruleTester = new RuleTester({ }); // make sure each test is completely isolated -// there was some weird behaviour with the mixed ts/tsx test cases without this +// there was some weird behavior with the mixed ts/tsx test cases without this afterEach(() => { clearCaches(); }); From 5322527f519037931c996acecce862ac653cc71b Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 12 Jan 2020 04:30:40 +0100 Subject: [PATCH 6/6] test(eslint-plugin): improve tests --- packages/eslint-plugin/package.json | 1 - .../no-unnecessary-type-assertion.test.ts | 19 ++++++------------- yarn.lock | 18 ------------------ 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index e748ace2e3ca..ee3800c64783 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -50,7 +50,6 @@ "@types/json-schema": "^7.0.3", "@types/marked": "^0.7.1", "@types/prettier": "^1.18.2", - "@types/react": "^16.9.2", "chalk": "^3.0.0", "marked": "^0.7.0", "prettier": "*", diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts index 6cbf1baf2d39..595d1961932c 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-type-assertion.test.ts @@ -1,4 +1,3 @@ -import { clearCaches } from '@typescript-eslint/parser'; import path from 'path'; import rule from '../../src/rules/no-unnecessary-type-assertion'; import { RuleTester } from '../RuleTester'; @@ -13,12 +12,6 @@ const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', }); -// make sure each test is completely isolated -// there was some weird behavior with the mixed ts/tsx test cases without this -afterEach(() => { - clearCaches(); -}); - ruleTester.run('no-unnecessary-type-assertion', rule, { valid: [ 'const foo = 3 as number;', @@ -127,13 +120,13 @@ testFunction(value!) // https://github.com/typescript-eslint/typescript-eslint/issues/982 { code: ` -const React = require("react"); +declare namespace JSX { interface IntrinsicElements { div: { key?: string | number } } } function Test(props: { id?: null | string | number; }) { return
; -}; +} `, filename: path.join(rootDir, 'react.tsx'), }, @@ -350,22 +343,22 @@ class Mx { // https://github.com/typescript-eslint/typescript-eslint/issues/982 { code: ` -const React = require("react"); +declare namespace JSX { interface IntrinsicElements { div: { key?: string | number } } } function Test(props: { id?: string | number; }) { return
; -}; +} `, output: ` -const React = require("react"); +declare namespace JSX { interface IntrinsicElements { div: { key?: string | number } } } function Test(props: { id?: string | number; }) { return
; -}; +} `, errors: [ { diff --git a/yarn.lock b/yarn.lock index 687b548d3c26..44ae6ae504ca 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1425,19 +1425,6 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-1.18.3.tgz#64ff53329ce16139f17c3db9d3e0487199972cd8" integrity sha512-48rnerQdcZ26odp+HOvDGX8IcUkYOCuMc2BodWYTe956MqkHlOGAG4oFQ83cjZ0a4GAgj7mb4GUClxYd2Hlodg== -"@types/prop-types@*": - version "15.7.2" - resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.2.tgz#0e58ae66773d7fd7c372a493aff740878ec9ceaa" - integrity sha512-f8JzJNWVhKtc9dg/dyDNfliTKNOJSLa7Oht/ElZdF/UbMUmAH3rLmAk3ODNjw0mZajDEgatA03tRjB4+Dp/tzA== - -"@types/react@^16.9.2": - version "16.9.2" - resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.2.tgz#6d1765431a1ad1877979013906731aae373de268" - integrity sha512-jYP2LWwlh+FTqGd9v7ynUKZzjj98T8x7Yclz479QdRhHfuW9yQ+0jjnD31eXSXutmBpppj5PYNLYLRfnZJvcfg== - dependencies: - "@types/prop-types" "*" - csstype "^2.2.0" - "@types/semver@^6.0.1": version "6.0.2" resolved "https://registry.yarnpkg.com/@types/semver/-/semver-6.0.2.tgz#5e8b09f0e4af53034b1d0fb9977a277847836205" @@ -2807,11 +2794,6 @@ cssstyle@^1.0.0: dependencies: cssom "0.3.x" -csstype@^2.2.0: - version "2.6.6" - resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.6.tgz#c34f8226a94bbb10c32cc0d714afdf942291fc41" - integrity sha512-RpFbQGUE74iyPgvr46U9t1xoQBM8T4BL8SxrN66Le2xYAPSaDJJKeztV3awugusb3g3G9iL8StmkBBXhcbbXhg== - currently-unhandled@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea"