Last active
March 12, 2016 06:55
-
-
Save indexzero/0df4264d5a1121469d2e to your computer and use it in GitHub Desktop.
Demonstration of a subtle ESLint parser conflict with "prefer-const"
This file contains hidden or 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
{ | |
"parserOptions": { | |
"ecmaVersion": 6, | |
"sourceType": "module", | |
}, | |
"rules": { | |
"prefer-const": 2 | |
} | |
} |
This file contains hidden or 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
eslint -c .eslint.test.config test/prefer-const.js | |
prefer-const.js | |
7:5 error 'third' is never modified, use 'const' instead prefer-const | |
✖ 1 problem (1 error, 0 warnings) |
This file contains hidden or 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
# Simple as possible repo | |
$ node test/prefer-const.js | |
third = 0.10418695327825844 | |
third = 0.8143592826090753 | |
# | |
# Running the slightly more complicated mocha example | |
# demonstrates the common-place nature of the pattern. | |
# | |
$ mocha test/prefer-const.js | |
test suite | |
third = 0.9538288279436529 | |
✓ some test | |
third = 0.2518426834139973 | |
✓ some other test | |
2 passing (7ms) |
This file contains hidden or 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
'use strict'; | |
const assert = require('assert'); | |
describe('test suite', function () { | |
let first; | |
let second; | |
let third; | |
function setupTest() { | |
first = Math.random(); | |
second = Math.random(); | |
third = Math.random(); | |
console.log('third = %s', third); | |
} | |
it('some test', function () { | |
setupTest(); | |
assert.equal(typeof first, 'number'); | |
assert.equal(typeof second, 'number'); | |
}); | |
it('some other test', function () { | |
setupTest(); | |
assert.equal(typeof first, 'number'); | |
assert.equal(typeof second, 'number'); | |
}); | |
}); |
This file contains hidden or 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
'use strict'; | |
const assert = require('assert'); | |
let first; | |
let second; | |
let third; | |
function setupTest() { | |
first = Math.random(); | |
second = Math.random(); | |
third = Math.random(); | |
console.log('third = %s', third); | |
} | |
setupTest(); | |
assert.equal(typeof first, 'number'); | |
assert.equal(typeof second, 'number'); | |
setupTest(); | |
assert.equal(typeof first, 'number'); | |
assert.equal(typeof second, 'number'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment