Path: blob/main/tests/src/rules/no-mutable-exports.js
829 views
import { test } from '../utils';1import { RuleTester } from 'eslint';2import rule from 'rules/no-mutable-exports';34const ruleTester = new RuleTester();56ruleTester.run('no-mutable-exports', rule, {7valid: [8test({ code: 'export const count = 1' }),9test({ code: 'export function getCount() {}' }),10test({ code: 'export class Counter {}' }),11test({ code: 'export default count = 1' }),12test({ code: 'export default function getCount() {}' }),13test({ code: 'export default class Counter {}' }),14test({ code: 'const count = 1\nexport { count }' }),15test({ code: 'const count = 1\nexport { count as counter }' }),16test({ code: 'const count = 1\nexport default count' }),17test({ code: 'const count = 1\nexport { count as default }' }),18test({ code: 'function getCount() {}\nexport { getCount }' }),19test({ code: 'function getCount() {}\nexport { getCount as getCounter }' }),20test({ code: 'function getCount() {}\nexport default getCount' }),21test({ code: 'function getCount() {}\nexport { getCount as default }' }),22test({ code: 'class Counter {}\nexport { Counter }' }),23test({ code: 'class Counter {}\nexport { Counter as Count }' }),24test({ code: 'class Counter {}\nexport default Counter' }),25test({ code: 'class Counter {}\nexport { Counter as default }' }),26test({27parser: require.resolve('babel-eslint'),28code: 'export Something from "./something";',29}),30test({31parser: require.resolve('babel-eslint'),32code: 'type Foo = {}\nexport type {Foo}',33}),34],35invalid: [36test({37code: 'export let count = 1',38errors: ['Exporting mutable \'let\' binding, use \'const\' instead.'],39}),40test({41code: 'export var count = 1',42errors: ['Exporting mutable \'var\' binding, use \'const\' instead.'],43}),44test({45code: 'let count = 1\nexport { count }',46errors: ['Exporting mutable \'let\' binding, use \'const\' instead.'],47}),48test({49code: 'var count = 1\nexport { count }',50errors: ['Exporting mutable \'var\' binding, use \'const\' instead.'],51}),52test({53code: 'let count = 1\nexport { count as counter }',54errors: ['Exporting mutable \'let\' binding, use \'const\' instead.'],55}),56test({57code: 'var count = 1\nexport { count as counter }',58errors: ['Exporting mutable \'var\' binding, use \'const\' instead.'],59}),60test({61code: 'let count = 1\nexport default count',62errors: ['Exporting mutable \'let\' binding, use \'const\' instead.'],63}),64test({65code: 'var count = 1\nexport default count',66errors: ['Exporting mutable \'var\' binding, use \'const\' instead.'],67}),6869// todo: undeclared globals70// test({71// code: 'count = 1\nexport { count }',72// errors: ['Exporting mutable global binding, use \'const\' instead.'],73// }),74// test({75// code: 'count = 1\nexport default count',76// errors: ['Exporting mutable global binding, use \'const\' instead.'],77// }),78],79});808182