Skip to content

Instantly share code, notes, and snippets.

@indexzero
Last active March 12, 2016 06:55
Show Gist options
  • Save indexzero/0df4264d5a1121469d2e to your computer and use it in GitHub Desktop.
Save indexzero/0df4264d5a1121469d2e to your computer and use it in GitHub Desktop.
Demonstration of a subtle ESLint parser conflict with "prefer-const"
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
},
"rules": {
"prefer-const": 2
}
}
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)
# 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)
'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');
});
});
'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