|
| 1 | +import {test} from '../utils' |
| 2 | +import {RuleTester} from 'eslint' |
| 3 | +import rule from 'rules/no-mutable-exports' |
| 4 | + |
| 5 | +const ruleTester = new RuleTester() |
| 6 | + |
| 7 | +ruleTester.run('no-mutable-exports', rule, { |
| 8 | + valid: [ |
| 9 | + test({ code: 'export const count = 1'}), |
| 10 | + test({ code: 'export function getCount() {}'}), |
| 11 | + test({ code: 'export class Counter {}'}), |
| 12 | + test({ code: 'export default count = 1'}), |
| 13 | + test({ code: 'export default function getCount() {}'}), |
| 14 | + test({ code: 'export default class Counter {}'}), |
| 15 | + test({ code: 'const count = 1\nexport { count }'}), |
| 16 | + test({ code: 'const count = 1\nexport { count as counter }'}), |
| 17 | + test({ code: 'const count = 1\nexport default count'}), |
| 18 | + test({ code: 'const count = 1\nexport { count as default }'}), |
| 19 | + test({ code: 'function getCount() {}\nexport { getCount }'}), |
| 20 | + test({ code: 'function getCount() {}\nexport { getCount as getCounter }'}), |
| 21 | + test({ code: 'function getCount() {}\nexport default getCount'}), |
| 22 | + test({ code: 'function getCount() {}\nexport { getCount as default }'}), |
| 23 | + test({ code: 'class Counter {}\nexport { Counter }'}), |
| 24 | + test({ code: 'class Counter {}\nexport { Counter as Count }'}), |
| 25 | + test({ code: 'class Counter {}\nexport default Counter'}), |
| 26 | + test({ code: 'class Counter {}\nexport { Counter as default }'}), |
| 27 | + ], |
| 28 | + invalid: [ |
| 29 | + test({ |
| 30 | + code: 'export let count = 1', |
| 31 | + errors: ['Exporting mutable \'let\' binding, use \'const\' instead.'], |
| 32 | + }), |
| 33 | + test({ |
| 34 | + code: 'export var count = 1', |
| 35 | + errors: ['Exporting mutable \'var\' binding, use \'const\' instead.'], |
| 36 | + }), |
| 37 | + test({ |
| 38 | + code: 'let count = 1\nexport { count }', |
| 39 | + errors: ['Exporting mutable \'let\' binding, use \'const\' instead.'], |
| 40 | + }), |
| 41 | + test({ |
| 42 | + code: 'var count = 1\nexport { count }', |
| 43 | + errors: ['Exporting mutable \'var\' binding, use \'const\' instead.'], |
| 44 | + }), |
| 45 | + test({ |
| 46 | + code: 'let count = 1\nexport { count as counter }', |
| 47 | + errors: ['Exporting mutable \'let\' binding, use \'const\' instead.'], |
| 48 | + }), |
| 49 | + test({ |
| 50 | + code: 'var count = 1\nexport { count as counter }', |
| 51 | + errors: ['Exporting mutable \'var\' binding, use \'const\' instead.'], |
| 52 | + }), |
| 53 | + test({ |
| 54 | + code: 'let count = 1\nexport default count', |
| 55 | + errors: ['Exporting mutable \'let\' binding, use \'const\' instead.'], |
| 56 | + }), |
| 57 | + test({ |
| 58 | + code: 'var count = 1\nexport default count', |
| 59 | + errors: ['Exporting mutable \'var\' binding, use \'const\' instead.'], |
| 60 | + }), |
| 61 | + ], |
| 62 | +}) |
0 commit comments