Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(rule-tester): use cwd option to set base path for tests with file name#10201
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
ef3176a
50ed82b
538f4cb
72ff7d5
1e47a9e
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
/* eslint-disable perfectionist/sort-objects */ | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'; | ||
import { RuleTester } from '../src/RuleTester'; | ||
const rule = ESLintUtils.RuleCreator.withoutDocs({ | ||
meta: { | ||
@@ -11,33 +12,68 @@ const rule = ESLintUtils.RuleCreator.withoutDocs({ | ||
}, | ||
messages: { | ||
foo: 'It works', | ||
createError: 'Create error', | ||
}, | ||
schema: [], | ||
type: 'problem', | ||
hasSuggestions: true, | ||
}, | ||
defaultOptions: [], | ||
create: context => ({ | ||
Program(node): void { | ||
context.report({ | ||
node, | ||
messageId: 'foo', | ||
suggest: | ||
node.body.length === 1 && | ||
node.body[0].type === AST_NODE_TYPES.EmptyStatement | ||
? [ | ||
{ | ||
messageId: 'createError', | ||
fix(fixer): TSESLint.RuleFix { | ||
return fixer.replaceText(node, '//'); | ||
}, | ||
}, | ||
] | ||
: [], | ||
}); | ||
}, | ||
}), | ||
}); | ||
describe('rule tester filename', () => { | ||
new RuleTester().run('without tsconfigRootDir', rule, { | ||
invalid: [ | ||
{ | ||
name: 'absolute path', | ||
code: '_', | ||
errors: [{ messageId: 'foo' }], | ||
filename: '/an-absolute-path/foo.js', | ||
}, | ||
{ | ||
name: 'relative path above project', | ||
code: '_', | ||
errors: [{ messageId: 'foo' }], | ||
filename: '../foo.js', | ||
}, | ||
], | ||
valid: [], | ||
}); | ||
new RuleTester({ | ||
languageOptions: { | ||
parserOptions: { tsconfigRootDir: '/some/path/that/totally/exists/' }, | ||
}, | ||
}).run('with tsconfigRootDir', rule, { | ||
invalid: [ | ||
{ | ||
name: 'absolute path', | ||
code: '_', | ||
errors: [{ messageId: 'foo' }], | ||
filename: '/an-absolute-path/foo.js', | ||
}, | ||
{ | ||
name: 'relative path above project', | ||
code: '_', | ||
errors: [{ messageId: 'foo' }], | ||
filename: '../foo.js', | ||
@@ -46,3 +82,52 @@ describe('rule tester filename', () => { | ||
valid: [], | ||
}); | ||
}); | ||
describe('rule tester suggestion syntax error checks', () => { | ||
new RuleTester().run('verifies suggestion with absolute path', rule, { | ||
invalid: [ | ||
{ | ||
code: ';', | ||
errors: [ | ||
{ | ||
messageId: 'foo', | ||
suggestions: [{ messageId: 'createError', output: '//' }], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This isn't a syntax error, right? Cos a line comment is valid. We need something invalid like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. | ||
}, | ||
], | ||
filename: '/an-absolute-path/foo.js', | ||
}, | ||
], | ||
valid: [], | ||
}); | ||
new RuleTester().run('verifies suggestion with relative path', rule, { | ||
invalid: [ | ||
{ | ||
code: ';', | ||
errors: [ | ||
{ | ||
messageId: 'foo', | ||
suggestions: [{ messageId: 'createError', output: '//' }], | ||
}, | ||
], | ||
filename: '../foo.js', | ||
}, | ||
], | ||
valid: [], | ||
}); | ||
new RuleTester().run('verifies suggestion with no path', rule, { | ||
invalid: [ | ||
{ | ||
code: ';', | ||
errors: [ | ||
{ | ||
messageId: 'foo', | ||
suggestions: [{ messageId: 'createError', output: '//' }], | ||
}, | ||
], | ||
}, | ||
], | ||
valid: [], | ||
}); | ||
}); |
Uh oh!
There was an error while loading.Please reload this page.