From 802e3471ed1a1664dfd74d5716237934b08875ca Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Fri, 24 Jan 2020 09:02:00 -0800 Subject: [PATCH] chore(eslint-plugin): use getFixturesRootDir in tests (#1506) --- .../tests/rules/no-dynamic-delete.test.ts | 11 +++++------ .../tests/rules/no-unnecessary-condition.test.ts | 13 ++++++------- .../tests/rules/no-unnecessary-qualifier.test.ts | 13 ++++++------- .../rules/no-unnecessary-type-arguments.test.ts | 11 +++++------ .../rules/no-unnecessary-type-assertion.test.ts | 2 +- .../tests/rules/prefer-includes.test.ts | 9 ++++----- .../tests/rules/prefer-nullish-coalescing.test.ts | 5 ++--- .../tests/rules/prefer-regexp-exec.test.ts | 5 ++--- .../rules/prefer-string-starts-ends-with.test.ts | 5 ++--- .../tests/rules/require-array-sort-compare.test.ts | 5 ++--- .../tests/rules/restrict-plus-operands.test.ts | 5 ++--- .../rules/restrict-template-expressions.test.ts | 5 ++--- .../tests/rules/strict-boolean-expressions.test.ts | 5 ++--- .../tests/rules/unbound-method.test.ts | 5 ++--- 14 files changed, 43 insertions(+), 56 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/no-dynamic-delete.test.ts b/packages/eslint-plugin/tests/rules/no-dynamic-delete.test.ts index aa12c33c9e5..5a88fbff10c 100644 --- a/packages/eslint-plugin/tests/rules/no-dynamic-delete.test.ts +++ b/packages/eslint-plugin/tests/rules/no-dynamic-delete.test.ts @@ -1,15 +1,14 @@ -import path from 'path'; import rule from '../../src/rules/no-dynamic-delete'; -import { RuleTester } from '../RuleTester'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; + +const rootPath = getFixturesRootDir(); -const rootDir = path.join(process.cwd(), 'tests/fixtures'); const ruleTester = new RuleTester({ + parser: '@typescript-eslint/parser', parserOptions: { - ecmaVersion: 2015, - tsconfigRootDir: rootDir, + tsconfigRootDir: rootPath, project: './tsconfig.json', }, - parser: '@typescript-eslint/parser', }); ruleTester.run('no-dynamic-delete', rule, { diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts index 1a7abc30f46..0728b9202b9 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts @@ -1,15 +1,14 @@ -import path from 'path'; -import rule, { - Options, - MessageId, -} from '../../src/rules/no-unnecessary-condition'; -import { RuleTester } from '../RuleTester'; import { TestCaseError, InvalidTestCase, } from '@typescript-eslint/experimental-utils/dist/ts-eslint'; +import rule, { + Options, + MessageId, +} from '../../src/rules/no-unnecessary-condition'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; -const rootPath = path.join(process.cwd(), 'tests/fixtures/'); +const rootPath = getFixturesRootDir(); const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts index 75236704c85..68e0e258383 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-qualifier.test.ts @@ -1,21 +1,20 @@ -import path from 'path'; -import rule from '../../src/rules/no-unnecessary-qualifier'; -import { RuleTester } from '../RuleTester'; import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; +import rule from '../../src/rules/no-unnecessary-qualifier'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; -const messageId = 'unnecessaryQualifier'; -const rootPath = path.join(process.cwd(), 'tests/fixtures/'); +const rootPath = getFixturesRootDir(); const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', parserOptions: { + sourceType: 'module', tsconfigRootDir: rootPath, project: './tsconfig.json', - sourceType: 'module', - ecmaVersion: 6, }, }); +const messageId = 'unnecessaryQualifier'; + ruleTester.run('no-unnecessary-qualifier', rule, { valid: [ ` diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-type-arguments.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-type-arguments.test.ts index ca81774d3dd..11ff8344698 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-type-arguments.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-type-arguments.test.ts @@ -1,16 +1,15 @@ -import path from 'path'; import rule from '../../src/rules/no-unnecessary-type-arguments'; -import { RuleTester } from '../RuleTester'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; + +const rootPath = getFixturesRootDir(); -const rootDir = path.join(process.cwd(), 'tests/fixtures'); const ruleTester = new RuleTester({ + parser: '@typescript-eslint/parser', parserOptions: { - ecmaVersion: 2015, sourceType: 'module', - tsconfigRootDir: rootDir, + tsconfigRootDir: rootPath, project: './tsconfig.json', }, - parser: '@typescript-eslint/parser', }); ruleTester.run('no-unnecessary-type-arguments', rule, { 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 3d5c958c3cc..e7248a9693e 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 @@ -5,7 +5,7 @@ import { RuleTester } from '../RuleTester'; const rootDir = path.resolve(__dirname, '../fixtures/'); const ruleTester = new RuleTester({ parserOptions: { - ecmaVersion: 2015, + sourceType: 'module', tsconfigRootDir: rootDir, project: './tsconfig.json', }, diff --git a/packages/eslint-plugin/tests/rules/prefer-includes.test.ts b/packages/eslint-plugin/tests/rules/prefer-includes.test.ts index 6094f3adee6..dac14615851 100644 --- a/packages/eslint-plugin/tests/rules/prefer-includes.test.ts +++ b/packages/eslint-plugin/tests/rules/prefer-includes.test.ts @@ -1,12 +1,9 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; -import path from 'path'; import rule from '../../src/rules/prefer-includes'; import * as util from '../../src/util'; -import { RuleTester } from '../RuleTester'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; -const rootPath = path.join(process.cwd(), 'tests/fixtures/'); - -type MessageIds = util.InferMessageIdsTypeFromRule; +const rootPath = getFixturesRootDir(); const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', @@ -16,6 +13,8 @@ const ruleTester = new RuleTester({ }, }); +type MessageIds = util.InferMessageIdsTypeFromRule; + type InvalidTestCase = TSESLint.InvalidTestCase; type ValidTestCase = TSESLint.ValidTestCase | string; function addOptional(cases: ValidTestCase[]): ValidTestCase[]; diff --git a/packages/eslint-plugin/tests/rules/prefer-nullish-coalescing.test.ts b/packages/eslint-plugin/tests/rules/prefer-nullish-coalescing.test.ts index 6a12c6d2138..40a8916317c 100644 --- a/packages/eslint-plugin/tests/rules/prefer-nullish-coalescing.test.ts +++ b/packages/eslint-plugin/tests/rules/prefer-nullish-coalescing.test.ts @@ -1,12 +1,11 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; -import path from 'path'; import rule, { MessageIds, Options, } from '../../src/rules/prefer-nullish-coalescing'; -import { RuleTester } from '../RuleTester'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; -const rootPath = path.join(process.cwd(), 'tests/fixtures/'); +const rootPath = getFixturesRootDir(); const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', diff --git a/packages/eslint-plugin/tests/rules/prefer-regexp-exec.test.ts b/packages/eslint-plugin/tests/rules/prefer-regexp-exec.test.ts index 98381cda6a1..045c36206ee 100644 --- a/packages/eslint-plugin/tests/rules/prefer-regexp-exec.test.ts +++ b/packages/eslint-plugin/tests/rules/prefer-regexp-exec.test.ts @@ -1,8 +1,7 @@ -import path from 'path'; import rule from '../../src/rules/prefer-regexp-exec'; -import { RuleTester } from '../RuleTester'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; -const rootPath = path.join(process.cwd(), 'tests/fixtures/'); +const rootPath = getFixturesRootDir(); const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', diff --git a/packages/eslint-plugin/tests/rules/prefer-string-starts-ends-with.test.ts b/packages/eslint-plugin/tests/rules/prefer-string-starts-ends-with.test.ts index 416fab6e02e..0022c37cb2f 100644 --- a/packages/eslint-plugin/tests/rules/prefer-string-starts-ends-with.test.ts +++ b/packages/eslint-plugin/tests/rules/prefer-string-starts-ends-with.test.ts @@ -1,9 +1,8 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; -import path from 'path'; import rule from '../../src/rules/prefer-string-starts-ends-with'; -import { RuleTester } from '../RuleTester'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; -const rootPath = path.join(process.cwd(), 'tests/fixtures/'); +const rootPath = getFixturesRootDir(); const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', diff --git a/packages/eslint-plugin/tests/rules/require-array-sort-compare.test.ts b/packages/eslint-plugin/tests/rules/require-array-sort-compare.test.ts index 1dae0d37f3d..d3a49c60f65 100644 --- a/packages/eslint-plugin/tests/rules/require-array-sort-compare.test.ts +++ b/packages/eslint-plugin/tests/rules/require-array-sort-compare.test.ts @@ -1,8 +1,7 @@ -import path from 'path'; import rule from '../../src/rules/require-array-sort-compare'; -import { RuleTester } from '../RuleTester'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; -const rootPath = path.join(process.cwd(), 'tests/fixtures/'); +const rootPath = getFixturesRootDir(); const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', diff --git a/packages/eslint-plugin/tests/rules/restrict-plus-operands.test.ts b/packages/eslint-plugin/tests/rules/restrict-plus-operands.test.ts index 5d979706f84..6270b61eec3 100644 --- a/packages/eslint-plugin/tests/rules/restrict-plus-operands.test.ts +++ b/packages/eslint-plugin/tests/rules/restrict-plus-operands.test.ts @@ -1,8 +1,7 @@ -import path from 'path'; import rule from '../../src/rules/restrict-plus-operands'; -import { RuleTester } from '../RuleTester'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; -const rootPath = path.join(process.cwd(), 'tests/fixtures/'); +const rootPath = getFixturesRootDir(); const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', diff --git a/packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts b/packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts index ef7657d6a00..cdf59b0c819 100644 --- a/packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts +++ b/packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts @@ -1,8 +1,7 @@ -import path from 'path'; import rule from '../../src/rules/restrict-template-expressions'; -import { RuleTester } from '../RuleTester'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; -const rootPath = path.join(process.cwd(), 'tests/fixtures/'); +const rootPath = getFixturesRootDir(); const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', diff --git a/packages/eslint-plugin/tests/rules/strict-boolean-expressions.test.ts b/packages/eslint-plugin/tests/rules/strict-boolean-expressions.test.ts index 244d8511dba..cf6dbd5cd36 100644 --- a/packages/eslint-plugin/tests/rules/strict-boolean-expressions.test.ts +++ b/packages/eslint-plugin/tests/rules/strict-boolean-expressions.test.ts @@ -1,8 +1,7 @@ -import path from 'path'; import rule from '../../src/rules/strict-boolean-expressions'; -import { RuleTester } from '../RuleTester'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; -const rootPath = path.join(process.cwd(), 'tests/fixtures/'); +const rootPath = getFixturesRootDir(); const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', diff --git a/packages/eslint-plugin/tests/rules/unbound-method.test.ts b/packages/eslint-plugin/tests/rules/unbound-method.test.ts index 6b5fd5500d4..dcf58b6447e 100644 --- a/packages/eslint-plugin/tests/rules/unbound-method.test.ts +++ b/packages/eslint-plugin/tests/rules/unbound-method.test.ts @@ -1,9 +1,8 @@ import { TSESLint } from '@typescript-eslint/experimental-utils'; -import path from 'path'; import rule, { MessageIds, Options } from '../../src/rules/unbound-method'; -import { RuleTester } from '../RuleTester'; +import { RuleTester, getFixturesRootDir } from '../RuleTester'; -const rootPath = path.join(process.cwd(), 'tests/fixtures/'); +const rootPath = getFixturesRootDir(); const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser',