Skip to content
Permalink
Browse files

Fix: allow extending @scope/eslint/file (fixes #4800)

Also:

- Fix english typos.
- Add failing test.
- Fix extending @scope/eslint/file bug.
  • Loading branch information...
satazor committed Dec 27, 2015
1 parent 6b71a63 commit f500d7db891bdbd3458a8db51d68fde6ece4e0bd
@@ -360,8 +360,9 @@ function resolve(filePath) {
var scopedPackageShortcutRegex = /^(@[^\/]+)(?:\/(?:eslint-config)?)?$/;
if (scopedPackageShortcutRegex.test(filePath)) {
filePath = filePath.replace(scopedPackageShortcutRegex, "$1/eslint-config");
} else if (filePath.split("/")[1].indexOf("eslint-config-") !== 0) {
// for scoped packages, insert the eslint-config after the first /
} else if (!/^eslint-config(-|$)/.test(filePath.split("/")[1])) {
// for scoped packages, insert the eslint-config after the first / unless
// the path is already @scope/eslint or @scope/eslint-config-xxx
filePath = filePath.replace(/^@([^\/]+)\/(.*)$/, "@$1/eslint-config-$2");
}
} else if (filePath.indexOf("eslint-config-") !== 0) {

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,12 @@
{
"extends": "@scope/eslint-config/foo",

"rules": {
"quotes": [2, "double"],
"valid-jsdoc": 0
},

"env": {
"browser": false
}
}
@@ -884,6 +884,30 @@ describe("Config", function() {
assertConfigsEqual(actual, expected);
});

it("should extend package sub-configuration with prefix", function() {

var configDeps = {};
configDeps["./config/config-file"] = proxyquire("../../lib/config/config-file", {
"@scope/eslint-config/foo": {
rules: {
eqeqeq: 2
}
}
});

var StubbedConfig = proxyquire("../../lib/config", configDeps);

var configPath = path.resolve(__dirname, "../fixtures/config-extends/scoped-package9/.eslintrc"),
configHelper = new StubbedConfig({ useEslintrc: false, configFile: configPath, cwd: process.cwd() }),
expected = {
rules: { "quotes": [2, "double"], "eqeqeq": 2, "valid-jsdoc": 0 },
env: { "browser": false }
},
actual = configHelper.getConfig(configPath);

assertConfigsEqual(actual, expected);
});

it("should not modify a scoped package named 'eslint-config'", function() {

var configDeps = {};
@@ -994,20 +1018,12 @@ describe("Config", function() {
var StubbedConfig = proxyquire("../../lib/config", configDeps);

var configPath = path.resolve(__dirname, "../fixtures/config-extends/package3/.eslintrc"),
configHelper = new StubbedConfig({ useEslintrc: true, configFile: configPath, cwd: process.cwd() }),
configHelper = new StubbedConfig({ useEslintrc: false, configFile: configPath, cwd: process.cwd() }),
expected = {
rules: { "quotes": [2, "double"], "eqeqeq": 2, "valid-jsdoc": 0 },
env: { "browser": false }
};

// Reason to override this function in this special case is that I dont want it to keep looking into the
// chain of parent directries for .eslintrc or package.json file for configs.
// If that is allowed then the expected outcome will change based on the machine you are running this test.
sinon.stub(configHelper, "findLocalConfigFiles").returns([
path.resolve(__dirname, "../fixtures/config-extends/package3/.eslintrc")
]);

var actual = configHelper.getConfig(configPath);
},
actual = configHelper.getConfig(configPath);

assertConfigsEqual(actual, expected);
});
@@ -1026,20 +1042,12 @@ describe("Config", function() {
var StubbedConfig = proxyquire("../../lib/config", configDeps);

var configPath = path.resolve(__dirname, "../fixtures/config-extends/scoped-package3/.eslintrc"),
configHelper = new StubbedConfig({ useEslintrc: true, configFile: configPath, cwd: process.cwd() }),
configHelper = new StubbedConfig({ useEslintrc: false, configFile: configPath, cwd: process.cwd() }),
expected = {
rules: { "quotes": [2, "double"], "eqeqeq": 2, "valid-jsdoc": 0 },
env: { "browser": false }
};

// Reason to override this function in this special case is that I dont want it to keep looking into the
// chain of parent directries for .eslintrc or package.json file for configs.
// If that is allowed then the expected outcome will change based on the machine you are running this test.
sinon.stub(configHelper, "findLocalConfigFiles").returns([
path.resolve(__dirname, "../fixtures/config-extends/scoped-package3/.eslintrc")
]);

var actual = configHelper.getConfig(configPath);
},
actual = configHelper.getConfig(configPath);

assertConfigsEqual(actual, expected);
});
@@ -1064,8 +1072,8 @@ describe("Config", function() {
env: { "browser": false }
};

// Reason to override this function in this special case is that I dont want it to keep looking into the
// chain of parent directries for .eslintrc or package.json file for configs.
// Reason to override this function in this special case is that I don't want it to keep looking into the
// chain of parent directories for .eslintrc or package.json file for configs.
// If that is allowed then the expected outcome will change based on the machine you are running this test.
sinon.stub(configHelper, "findLocalConfigFiles").returns([
path.resolve(__dirname, "../fixtures/config-extends/package2/.eslintrc")

0 comments on commit f500d7d

Please sign in to comment.
You can’t perform that action at this time.