|
| 1 | +import { test } from '../utils' |
| 2 | +import * as path from 'path' |
| 3 | + |
| 4 | +import { RuleTester } from 'eslint' |
| 5 | + |
| 6 | +const ruleTester = new RuleTester() |
| 7 | + , rule = require('rules/no-unassigned-import') |
| 8 | + |
| 9 | +const error = { |
| 10 | + ruleId: 'no-unassigned-import', |
| 11 | + message: 'Imported module should be assigned' |
| 12 | +} |
| 13 | + |
| 14 | +ruleTester.run('no-unassigned-import', rule, { |
| 15 | + valid: [ |
| 16 | + test({ code: 'import _ from "lodash"'}), |
| 17 | + test({ code: 'import _, {foo} from "lodash"'}), |
| 18 | + test({ code: 'import _, {foo as bar} from "lodash"'}), |
| 19 | + test({ code: 'import {foo as bar} from "lodash"'}), |
| 20 | + test({ code: 'import * as _ from "lodash"'}), |
| 21 | + test({ code: 'import _ from "./"'}), |
| 22 | + test({ code: 'const _ = require("lodash")'}), |
| 23 | + test({ code: 'const {foo} = require("lodash")'}), |
| 24 | + test({ code: 'const {foo: bar} = require("lodash")'}), |
| 25 | + test({ code: 'const [a, b] = require("lodash")'}), |
| 26 | + test({ code: 'const _ = require("lodash")'}), |
| 27 | + test({ code: 'const _ = require("./")'}), |
| 28 | + test({ code: 'foo(require("lodash"))'}), |
| 29 | + test({ code: 'require("lodash").foo'}), |
| 30 | + test({ code: 'require("lodash").foo()'}), |
| 31 | + test({ code: 'require("lodash")()'}), |
| 32 | + ], |
| 33 | + invalid: [ |
| 34 | + test({ |
| 35 | + code: 'import "lodash"', |
| 36 | + errors: [error], |
| 37 | + }), |
| 38 | + test({ |
| 39 | + code: 'require("lodash")', |
| 40 | + errors: [error], |
| 41 | + }), |
| 42 | + ], |
| 43 | +}) |
0 commit comments