-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: prohibt-import ruleにテストを追加する (#7)
* chore: eslint ruleのテスト環境を用意する * test: prohibit-import ruleのテストを追加する * fix!(BREAKING CHANGE): prohibit-import ruleのリファクタリング * test: prohibit-import ruleのSchemaを変更するので、テストのoptionを修正する * fix!(BREAKING CHANGE): エラーメッセージをtargetごとにカスタマイズできるようにSchemaの変更する * test: Schemaを全体で統一するのでテストを修正する * fix! 複数のモジュールを監視し、それぞれメッセージをカスタマイズできるようにする
- Loading branch information
1 parent
fcc57e8
commit ddd74fc
Showing
5 changed files
with
2,628 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
moduleFileExtensions: ['js'], | ||
testMatch: ['**/test/**/*.+(js)'], | ||
roots: ['<rootDir>/'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
const rule = require("../rules/prohibit-import") | ||
const RuleTester = require("eslint").RuleTester | ||
|
||
const ruleTester = new RuleTester({ | ||
parserOptions: { | ||
sourceType: "module", | ||
ecmaVersion: 2015 | ||
}, | ||
}) | ||
|
||
ruleTester.run("prohibit-import-lodash", rule, { | ||
valid: [ | ||
{ | ||
code: `import _ from 'lodash-es'`, | ||
options: [ | ||
{ | ||
'^lodash$': { | ||
imported: true, | ||
}, | ||
} | ||
] | ||
}, | ||
{ | ||
code: `import { isEqual } from 'lodash-es'`, | ||
options: [ | ||
{ | ||
'^lodash$': { | ||
imported: ['isEqual'] | ||
}, | ||
} | ||
] | ||
}, | ||
{ | ||
code: `import { isEqaul } from 'lodash'`, | ||
options: [ | ||
{ | ||
'^lodash$': { | ||
imported: ['isEqual'] | ||
}, | ||
} | ||
] | ||
}, | ||
{ | ||
code: `import _ from 'lodash'`, | ||
options: [ | ||
{ | ||
'^lodash$': { | ||
imported: ['isEqual'] | ||
}, | ||
} | ||
] | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: `import _ from 'lodash'`, | ||
options: [ | ||
{ | ||
'^lodash$': { | ||
imported: true | ||
}, | ||
} | ||
], | ||
errors: [{ message: 'lodash は利用しないでください' }] | ||
}, | ||
{ | ||
code: `import { isEqual } from 'lodash'`, | ||
options: [ | ||
{ | ||
'^lodash$': { | ||
imported: true | ||
}, | ||
} | ||
], | ||
errors: [{ message: 'lodash は利用しないでください' }] | ||
}, | ||
{ | ||
code: `import { isEqual } from 'lodash'`, | ||
options: [ | ||
{ | ||
'^lodash$': { | ||
imported: ['isEqual'] | ||
}, | ||
} | ||
], | ||
errors: [{message: 'lodash/isEqual は利用しないでください'}] | ||
}, | ||
{ | ||
code: `import { isEqual } from 'lodash'`, | ||
options: [ | ||
{ | ||
'^lodash$': { | ||
imported: ['isEqual'], | ||
"reportMessage": "must not use {{module}}/{{export}}" | ||
}, | ||
} | ||
], | ||
errors: [{message: 'must not use lodash/isEqual'}] | ||
}, | ||
{ | ||
code: `import { isEqual } from 'lodash'`, | ||
options: [ | ||
{ | ||
'example': { | ||
imported: true, | ||
}, | ||
'^lodash$': { | ||
imported: ['isEqual'], | ||
reportMessage: "must not use {{module}}/{{export}}", | ||
}, | ||
} | ||
], | ||
errors: [{message: 'must not use lodash/isEqual'}] | ||
} | ||
] | ||
}) |
Oops, something went wrong.