Skip to content

Commit a27a188

Browse files
committed
feature: @putout/plugin-convert-const-to-let: exclude const, let, var
1 parent c4aadf5 commit a27a188

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

packages/plugin-convert-const-to-let/lib/convert-const-to-let.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
'use strict';
22

33
const {values} = Object;
4+
const isKeyword = (a) => [
5+
'export',
6+
'const',
7+
'let',
8+
'var',
9+
].includes(a);
410

511
module.exports.report = () => `Use 'let' when reassign`;
612

@@ -35,7 +41,7 @@ module.exports.traverse = ({push}) => ({
3541
if (!binding.path.isVariableDeclarator())
3642
continue;
3743

38-
if (binding.path.node.id.name === 'export')
44+
if (isKeyword(binding.path.node.id.name))
3945
continue;
4046

4147
if (parentPath.node.kind === 'const')

packages/plugin-convert-const-to-let/test/convert-const-to-let.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ test('plugin-convert-const-to-let: no report: export', (t) => {
6161
t.end();
6262
});
6363

64+
test('plugin-convert-const-to-let: no report: const-const', (t) => {
65+
t.noReport('const-const');
66+
t.end();
67+
});
68+
6469
test('plugin-convert-const-to-let: transform: split-variable-declarations', (t) => {
6570
t.transform('split-variable-declarations', {
6671
'split-variable-declaration': splitVariableDeclarations,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const a = 1,
2+
const b = 2;
3+
4+
const a1 = 1,
5+
let b1 = 2;
6+
7+
const a2 = 1,
8+
var b2 = 2;

0 commit comments

Comments
 (0)