Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test(eslint-plugin): add test cases for eslint rules#240

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bradzacher merged 4 commits intotypescript-eslint:masterfromarmano2:eslint-rules
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletionspackages/eslint-plugin/tests/RuleTester.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,9 @@ interface ValidTestCase<TOptions extends Readonly<any[]>> {
settings?: Record<string, any>;
parser?: string;
globals?: Record<string, boolean>;
env?: {
browser?: boolean;
};
}

interface InvalidTestCase<
Expand Down
250 changes: 246 additions & 4 deletionspackages/eslint-plugin/tests/eslint-rules/no-redeclare.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,55 @@
import rule from 'eslint/lib/rules/no-redeclare';
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
import { RuleTester } from '../RuleTester';

const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {}
ecmaVersion: 6
},
parser: '@typescript-eslint/parser'
});

ruleTester.run('no-redeclare', rule, {
valid: [
'var a = 3; var b = function() { var a = 10; };',
'var a = 3; a = 10;',
{
code: 'if (true) {\n let b = 2;\n} else { \nlet b = 3;\n}',
parserOptions: {
ecmaVersion: 6
}
},
'var Object = 0;',
{ code: 'var Object = 0;', options: [{ builtinGlobals: false }] },
{
code: 'var Object = 0;',
options: [{ builtinGlobals: true }],
parserOptions: { sourceType: 'module' }
},
{
code: 'var Object = 0;',
options: [{ builtinGlobals: true }],
parserOptions: { ecmaFeatures: { globalReturn: true } }
},
{ code: 'var top = 0;', env: { browser: true } },
{ code: 'var top = 0;', options: [{ builtinGlobals: true }] },
{
code: 'var top = 0;',
options: [{ builtinGlobals: true }],
parserOptions: { ecmaFeatures: { globalReturn: true } },
env: { browser: true }
},
{
code: 'var top = 0;',
options: [{ builtinGlobals: true }],
parserOptions: { sourceType: 'module' },
env: { browser: true }
},
{
code: 'var self = 1',
options: [{ builtinGlobals: true }],
env: { browser: false }
},
// https://github.com/eslint/typescript-eslint-parser/issues/443
`
const Foo = 1;
Expand All@@ -22,7 +60,211 @@ type Foo = 1;
function foo({ bar }: { bar: string }) {
console.log(bar);
}
`,
`
type AST<T extends ParserOptions> = TSESTree.Program &
(T['range'] extends true ? { range: [number, number] } : {}) &
(T['tokens'] extends true ? { tokens: TSESTree.Token[] } : {}) &
(T['comment'] extends true ? { comments: TSESTree.Comment[] } : {});
interface ParseAndGenerateServicesResult<T extends ParserOptions> {
ast: AST<T>;
services: ParserServices;
}
`,
`
function A<T>() {}
interface B<T> {}
type C<T> = Array<T>
class D<T> {}
`
],
invalid: []
invalid: [
{
code: 'var a = 3; var a = 10;',
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

ugh, we should consider PRing the base eslint to migrate their rules to messageId

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

yup we should :)

]
},
{
code: 'switch(foo) { case a: var b = 3;\ncase b: var b = 4}',
errors: [
{
message: "'b' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'var a = 3; var a = 10;',
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'var a = {}; var a = [];',
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'var a; function a() {}',
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'function a() {} function a() {}',
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'var a = function() { }; var a = function() { }',
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'var a = function() { }; var a = new Date();',
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'var a = 3; var a = 10; var a = 15;',
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any,
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'var a; var a;',
parserOptions: { sourceType: 'module' },
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'export var a; var a;',
parserOptions: { sourceType: 'module' },
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'var Object = 0;',
options: [{ builtinGlobals: true }],
errors: [
{
message: "'Object' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'var top = 0;',
options: [{ builtinGlobals: true }],
errors: [
{
message: "'top' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
],
env: { browser: true }
},
{
code: 'var a; var {a = 0, b: Object = 0} = {};',
options: [{ builtinGlobals: true }],
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any,
{
message: "'Object' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'var a; var {a = 0, b: Object = 0} = {};',
options: [{ builtinGlobals: true }],
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'var a; var {a = 0, b: Object = 0} = {};',
options: [{ builtinGlobals: true }],
parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } },
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},
{
code: 'var a; var {a = 0, b: Object = 0} = {};',
options: [{ builtinGlobals: false }],
parserOptions: { ecmaVersion: 6 },
errors: [
{
message: "'a' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
},

// Notifications of readonly are moved from no-undef: https://github.com/eslint/eslint/issues/4504
{
code: '/*global b:false*/ var b = 1;',
options: [{ builtinGlobals: true }],
errors: [
{
message: "'b' is already defined.",
type: AST_NODE_TYPES.Identifier
} as any
]
}
]
});
View file
Open in desktop

This file was deleted.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -214,7 +214,22 @@ export namespace Third {
`,
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
parser: '@typescript-eslint/parser'
}
},
// https://github.com/eslint/typescript-eslint-parser/issues/550
`
function test(file: Blob) {
const slice: typeof file.slice =
file.slice || (file as any).webkitSlice || (file as any).mozSlice
return slice
}
`,
// https://github.com/eslint/typescript-eslint-parser/issues/435
`
interface Foo {
bar: string
}
const bar = 'blah'
`
],
invalid: [
{
Expand DownExpand Up@@ -813,7 +828,7 @@ function foo() {
var bar = 1;
}
var bar;
`,
`,
parserOptions,
options: [{ variables: false }],
errors: [
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp