Skip to content

Commit 509205f

Browse files
TrottMylesBorins
authored andcommitted
tools: update to ESLint 4.1.1
PR-URL: #13946 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 8f664e5 commit 509205f

File tree

6 files changed

+95
-40
lines changed

6 files changed

+95
-40
lines changed

tools/eslint/lib/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ class Config {
6666
this.parser = options.parser;
6767
this.parserOptions = options.parserOptions || {};
6868

69+
this.configCache = new ConfigCache();
70+
6971
this.baseConfig = options.baseConfig
7072
? ConfigOps.merge({}, ConfigFile.loadObject(options.baseConfig, this))
7173
: { rules: {} };
7274
this.baseConfig.filePath = "";
7375
this.baseConfig.baseDirectory = this.options.cwd;
7476

75-
this.configCache = new ConfigCache();
7677
this.configCache.setConfig(this.baseConfig.filePath, this.baseConfig);
7778
this.configCache.setMergedVectorConfig(this.baseConfig.filePath, this.baseConfig);
7879

tools/eslint/lib/config/config-cache.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,38 @@ function hash(vector) {
2424
//------------------------------------------------------------------------------
2525

2626
/**
27-
* Configuration caching class (not exported)
27+
* Configuration caching class
2828
*/
29-
class ConfigCache {
29+
module.exports = class ConfigCache {
3030

3131
constructor() {
32-
this.filePathCache = new Map();
32+
this.configFullNameCache = new Map();
3333
this.localHierarchyCache = new Map();
3434
this.mergedVectorCache = new Map();
3535
this.mergedCache = new Map();
3636
}
3737

3838
/**
3939
* Gets a config object from the cache for the specified config file path.
40-
* @param {string} configFilePath the absolute path to the config file
40+
* @param {string} configFullName the name of the configuration as used in the eslint config(e.g. 'plugin:node/recommended'),
41+
* or the absolute path to a config file. This should uniquely identify a config.
4142
* @returns {Object|null} config object, if found in the cache, otherwise null
4243
* @private
4344
*/
44-
getConfig(configFilePath) {
45-
return this.filePathCache.get(configFilePath);
45+
getConfig(configFullName) {
46+
return this.configFullNameCache.get(configFullName);
4647
}
4748

4849
/**
4950
* Sets a config object in the cache for the specified config file path.
50-
* @param {string} configFilePath the absolute path to the config file
51+
* @param {string} configFullName the name of the configuration as used in the eslint config(e.g. 'plugin:node/recommended'),
52+
* or the absolute path to a config file. This should uniquely identify a config.
5153
* @param {Object} config the config object to add to the cache
5254
* @returns {void}
5355
* @private
5456
*/
55-
setConfig(configFilePath, config) {
56-
this.filePathCache.set(configFilePath, config);
57+
setConfig(configFullName, config) {
58+
this.configFullNameCache.set(configFullName, config);
5759
}
5860

5961
/**
@@ -125,6 +127,4 @@ class ConfigCache {
125127
setMergedConfig(vector, config) {
126128
this.mergedCache.set(hash(vector), config);
127129
}
128-
}
129-
130-
module.exports = ConfigCache;
130+
};

tools/eslint/lib/config/config-file.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,15 @@ function normalizePackageName(name, prefix) {
488488
* @returns {Object} An object containing 3 properties:
489489
* - 'filePath' (required) the resolved path that can be used directly to load the configuration.
490490
* - 'configName' the name of the configuration inside the plugin.
491-
* - 'configFullName' the name of the configuration as used in the eslint config (e.g. 'plugin:node/recommended').
491+
* - 'configFullName' (required) the name of the configuration as used in the eslint config(e.g. 'plugin:node/recommended'),
492+
* or the absolute path to a config file. This should uniquely identify a config.
492493
* @private
493494
*/
494495
function resolve(filePath, relativeTo) {
495496
if (isFilePath(filePath)) {
496-
return { filePath: path.resolve(relativeTo || "", filePath) };
497+
const fullPath = path.resolve(relativeTo || "", filePath);
498+
499+
return { filePath: fullPath, configFullName: fullPath };
497500
}
498501
let normalizedPackageName;
499502

@@ -510,7 +513,7 @@ function resolve(filePath, relativeTo) {
510513
normalizedPackageName = normalizePackageName(filePath, "eslint-config");
511514
debug(`Attempting to resolve ${normalizedPackageName}`);
512515
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo));
513-
return { filePath };
516+
return { filePath, configFullName: filePath };
514517

515518

516519
}
@@ -560,11 +563,12 @@ function loadFromDisk(resolvedPath, configContext) {
560563
/**
561564
* Loads a config object, applying extends if present.
562565
* @param {Object} configObject a config object to load
566+
* @param {Config} configContext Context for the config instance
563567
* @returns {Object} the config object with extends applied if present, or the passed config if not
564568
* @private
565569
*/
566-
function loadObject(configObject) {
567-
return configObject.extends ? applyExtends(configObject, "") : configObject;
570+
function loadObject(configObject, configContext) {
571+
return configObject.extends ? applyExtends(configObject, configContext, "") : configObject;
568572
}
569573

570574
/**
@@ -579,7 +583,7 @@ function loadObject(configObject) {
579583
function load(filePath, configContext, relativeTo) {
580584
const resolvedPath = resolve(filePath, relativeTo);
581585

582-
const cachedConfig = configContext.configCache.getConfig(resolvedPath.filePath);
586+
const cachedConfig = configContext.configCache.getConfig(resolvedPath.configFullName);
583587

584588
if (cachedConfig) {
585589
return cachedConfig;
@@ -590,7 +594,7 @@ function load(filePath, configContext, relativeTo) {
590594
if (config) {
591595
config.filePath = resolvedPath.filePath;
592596
config.baseDirectory = path.dirname(resolvedPath.filePath);
593-
configContext.configCache.setConfig(resolvedPath.filePath, config);
597+
configContext.configCache.setConfig(resolvedPath.configFullName, config);
594598
}
595599

596600
return config;

tools/eslint/lib/rules/indent.js

+58-8
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ class OffsetStorage {
220220

221221
/**
222222
* Sets the offset column of token B to match the offset column of token A.
223-
* This is different from matchIndentOf because it matches a *column*, even if baseToken is not
224-
* the first token on its line.
223+
* **WARNING**: This is different from matchIndentOf because it matches a *column*, even if baseToken is not
224+
* the first token on its line. In most cases, `matchIndentOf` should be used instead.
225225
* @param {Token} baseToken The first token
226226
* @param {Token} offsetToken The second token, whose offset should be matched to the first token
227227
* @returns {void}
@@ -239,12 +239,62 @@ class OffsetStorage {
239239
}
240240

241241
/**
242-
* Sets the desired offset of a token
243-
* @param {Token} token The token
244-
* @param {Token} offsetFrom The token that this is offset from
245-
* @param {number} offset The desired indent level
246-
* @returns {void}
247-
*/
242+
* Sets the desired offset of a token.
243+
*
244+
* This uses a line-based offset collapsing behavior to handle tokens on the same line.
245+
* For example, consider the following two cases:
246+
*
247+
* (
248+
* [
249+
* bar
250+
* ]
251+
* )
252+
*
253+
* ([
254+
* bar
255+
* ])
256+
*
257+
* Based on the first case, it's clear that the `bar` token needs to have an offset of 1 indent level (4 spaces) from
258+
* the `[` token, and the `[` token has to have an offset of 1 indent level from the `(` token. Since the `(` token is
259+
* the first on its line (with an indent of 0 spaces), the `bar` token needs to be offset by 2 indent levels (8 spaces)
260+
* from the start of its line.
261+
*
262+
* However, in the second case `bar` should only be indented by 4 spaces. This is because the offset of 1 indent level
263+
* between the `(` and the `[` tokens gets "collapsed" because the two tokens are on the same line. As a result, the
264+
* `(` token is mapped to the `[` token with an offset of 0, and the rule correctly decides that `bar` should be indented
265+
* by 1 indent level from the start of the line.
266+
*
267+
* This is useful because rule listeners can usually just call `setDesiredOffset` for all the tokens in the node,
268+
* without needing to check which lines those tokens are on.
269+
*
270+
* Note that since collapsing only occurs when two tokens are on the same line, there are a few cases where non-intuitive
271+
* behavior can occur. For example, consider the following cases:
272+
*
273+
* foo(
274+
* ).
275+
* bar(
276+
* baz
277+
* )
278+
*
279+
* foo(
280+
* ).bar(
281+
* baz
282+
* )
283+
*
284+
* Based on the first example, it would seem that `bar` should be offset by 1 indent level from `foo`, and `baz`
285+
* should be offset by 1 indent level from `bar`. However, this is not correct, because it would result in `baz`
286+
* being indented by 2 indent levels in the second case (since `foo`, `bar`, and `baz` are all on separate lines, no
287+
* collapsing would occur).
288+
*
289+
* Instead, the correct way would be to offset `baz` by 1 level from `bar`, offset `bar` by 1 level from the `)`, and
290+
* offset the `)` by 0 levels from `foo`. This ensures that the offset between `bar` and the `)` are correctly collapsed
291+
* in the second case.
292+
*
293+
* @param {Token} token The token
294+
* @param {Token} offsetFrom The token that `token` should be offset from
295+
* @param {number} offset The desired indent level
296+
* @returns {void}
297+
*/
248298
setDesiredOffset(token, offsetFrom, offset) {
249299
if (offsetFrom && token.loc.start.line === offsetFrom.loc.start.line) {
250300
this.matchIndentOf(offsetFrom, token);

tools/eslint/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/eslint/package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{
2-
"_from": "eslint@4.1.0",
3-
"_id": "eslint@4.1.0",
2+
"_from": "eslint@latest",
3+
"_id": "eslint@4.1.1",
44
"_inBundle": false,
5-
"_integrity": "sha1-u7VaKCIO4Itp2pVU1FprLr/X2RM=",
5+
"_integrity": "sha1-+svfz+Pg+s06i4DcmMTmwTrlgt8=",
66
"_location": "/eslint",
77
"_phantomChildren": {},
88
"_requested": {
9-
"type": "version",
9+
"type": "tag",
1010
"registry": true,
11-
"raw": "eslint@4.1.0",
11+
"raw": "eslint@latest",
1212
"name": "eslint",
1313
"escapedName": "eslint",
14-
"rawSpec": "4.1.0",
14+
"rawSpec": "latest",
1515
"saveSpec": null,
16-
"fetchSpec": "4.1.0"
16+
"fetchSpec": "latest"
1717
},
1818
"_requiredBy": [
1919
"#USER",
2020
"/"
2121
],
22-
"_resolved": "https://registry.npmjs.org/eslint/-/eslint-4.1.0.tgz",
23-
"_shasum": "bbb55a28220ee08b69da9554d45a6b2ebfd7d913",
24-
"_spec": "eslint@4.1.0",
22+
"_resolved": "https://registry.npmjs.org/eslint/-/eslint-4.1.1.tgz",
23+
"_shasum": "facbdfcfe3e0facd3a8b80dc98c4e6c13ae582df",
24+
"_spec": "eslint@latest",
2525
"_where": "/Users/trott/io.js/tools/eslint-tmp",
2626
"author": {
2727
"name": "Nicholas C. Zakas",
@@ -152,5 +152,5 @@
152152
"release": "node Makefile.js release",
153153
"test": "node Makefile.js test"
154154
},
155-
"version": "4.1.0"
155+
"version": "4.1.1"
156156
}

0 commit comments

Comments
 (0)