-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 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,23 @@ | ||
# no-mutable-exports | ||
|
||
Forbids the use of mutable exports with `var` or `let`. | ||
|
||
## Rule Details | ||
|
||
Valid: | ||
|
||
```js | ||
export const count = 1 | ||
export function getCount() {} | ||
``` | ||
|
||
...whereas here exports will be reported: | ||
|
||
```js | ||
export let count = 2 | ||
export var count = 3 | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
If your environment correctly implements mutable export bindings. |
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,10 @@ | ||
module.exports = function (context) { | ||
return { | ||
'ExportNamedDeclaration': function (node) { | ||
const kind = node.declaration.kind | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if (kind === 'var' || kind === 'let') { | ||
context.report(node, `Exporting mutable '${kind}' binding, use const instead.`) | ||
} | ||
}, | ||
} | ||
} |
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,23 @@ | ||
import {test} from '../utils' | ||
import {RuleTester} from 'eslint' | ||
import rule from 'rules/no-mutable-exports' | ||
|
||
const ruleTester = new RuleTester() | ||
|
||
ruleTester.run('no-mutable-exports', rule, { | ||
valid: [ | ||
test({ code: 'export const count = 1'}), | ||
test({ code: 'export function getCount() {}'}), | ||
test({ code: 'export class Counter {}'}), | ||
], | ||
invalid: [ | ||
test({ | ||
code: 'export let count = 1', | ||
errors: ['Exporting mutable \'let\' binding, use const instead.'], | ||
}), | ||
test({ | ||
code: 'export var count = 1', | ||
errors: ['Exporting mutable \'var\' binding, use const instead.'], | ||
}), | ||
], | ||
}) |
Spec allows
declaration
to be null. IIRC it should be forexport { x as y }
.Can you add a
valid
test case for this and fix if needed?