|
| 1 | +import { test, SYNTAX_CASES } from '../utils' |
| 2 | +import { RuleTester } from 'eslint' |
| 3 | + |
| 4 | +const ruleTester = new RuleTester() |
| 5 | + , rule = require('rules/no-self-import') |
| 6 | + |
| 7 | +ruleTester.run('no-self-import', rule, { |
| 8 | + valid: [ |
| 9 | + test({ filename: 'foo', code: 'import "./bar"' }), |
| 10 | + test({ filename: 'foo', code: 'import "./bar.js"' }), |
| 11 | + test({ filename: 'foo.js', code: 'import "./bar"' }), |
| 12 | + test({ filename: 'foo.js', code: 'import "./bar.js"' }), |
| 13 | + test({ filename: 'foo.jsx', code: 'import "./bar"' }), |
| 14 | + test({ filename: 'foo.jsx', code: 'import "./bar.jsx"' }), |
| 15 | + test({ filename: 'foo.jsx', code: 'import "./foo.js"' }), |
| 16 | + |
| 17 | + // es7 |
| 18 | + test({ filename: 'foo.js', code: 'export bar, { foo } from "./bar";', parser: 'babel-eslint' }), |
| 19 | + test({ filename: 'foo.js', code: 'export bar from "./bar";', parser: 'babel-eslint' }), |
| 20 | + |
| 21 | + ...SYNTAX_CASES, |
| 22 | + ], |
| 23 | + |
| 24 | + invalid: [ |
| 25 | + test({ |
| 26 | + code: 'import "./foo";', |
| 27 | + filename: 'foo.jsx', |
| 28 | + errors: [ |
| 29 | + { message: 'Importing from the current file.', type: 'ImportDeclaration' }, |
| 30 | + ] |
| 31 | + }), |
| 32 | + |
| 33 | + test({ |
| 34 | + code: 'import "./foo.jsx";', |
| 35 | + filename: 'foo.jsx', |
| 36 | + errors: [ |
| 37 | + { message: 'Importing from the current file.', type: 'ImportDeclaration' }, |
| 38 | + ] |
| 39 | + }), |
| 40 | + |
| 41 | + test({ |
| 42 | + code: 'import foo from "./foo";', |
| 43 | + filename: 'foo.jsx', |
| 44 | + errors: [ |
| 45 | + { message: 'Importing from the current file.', type: 'ImportDeclaration' }, |
| 46 | + ] |
| 47 | + }), |
| 48 | + |
| 49 | + test({ |
| 50 | + code: 'import foo from "./foo.jsx";', |
| 51 | + filename: 'foo.jsx', |
| 52 | + errors: [ |
| 53 | + { message: 'Importing from the current file.', type: 'ImportDeclaration' }, |
| 54 | + ] |
| 55 | + }), |
| 56 | + |
| 57 | + test({ |
| 58 | + code: 'import { foo } from "./foo";', |
| 59 | + filename: 'foo.jsx', |
| 60 | + errors: [ |
| 61 | + { message: 'Importing from the current file.', type: 'ImportDeclaration' }, |
| 62 | + ] |
| 63 | + }), |
| 64 | + |
| 65 | + test({ |
| 66 | + code: 'import { foo } from "./foo.jsx";', |
| 67 | + filename: 'foo.jsx', |
| 68 | + errors: [ |
| 69 | + { message: 'Importing from the current file.', type: 'ImportDeclaration' }, |
| 70 | + ] |
| 71 | + }), |
| 72 | + ], |
| 73 | +}) |
0 commit comments