Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
fix up
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Chen committed Nov 10, 2016
1 parent fe0b8fd commit dfc718d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
29 changes: 14 additions & 15 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,22 +219,21 @@ export function extendConfigurationFile(targetConfig: IConfigurationFile,
const nextConfigRulesDirectory = arrayify(nextConfigSource.rulesDirectory);
combinedConfig.rulesDirectory = configRulesDirectory.concat(nextConfigRulesDirectory);

combinedConfig.rules = {};
for (const name of Object.keys(objectify(targetConfig.rules))) {
combinedConfig.rules[name] = targetConfig.rules[name];
}
// next config source overwrites the target config object
for (const name of Object.keys(objectify(nextConfigSource.rules))) {
combinedConfig.rules[name] = nextConfigSource.rules[name];
}
const combineProperties = (targetProperty: any, nextProperty: any) => {
let combinedProperty: any = {};
for (const name of Object.keys(objectify(targetProperty))) {
combinedProperty[name] = targetProperty[name];
}
// next config source overwrites the target config object
for (const name of Object.keys(objectify(nextProperty))) {
combinedProperty[name] = nextProperty[name];
}
return combinedProperty;
};

combinedConfig.jsRules = {};
for (const name of Object.keys(objectify(baseConfig.jsRules))) {
combinedConfig.jsRules[name] = baseConfig.jsRules[name];
}
for (const name of Object.keys(objectify(config.jsRules))) {
combinedConfig.jsRules[name] = config.jsRules[name];
}
combinedConfig.rules = combineProperties(targetConfig.rules, nextConfigSource.rules);
combinedConfig.jsRules = combineProperties(targetConfig.jsRules, nextConfigSource.jsRules);
combinedConfig.linterOptions = combineProperties(targetConfig.linterOptions, nextConfigSource.linterOptions);

return combinedConfig;
}
Expand Down
18 changes: 12 additions & 6 deletions test/configurationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe("Configuration", () => {
it("extendConfigurationFile", () => {
const EMPTY_CONFIG: IConfigurationFile = {
jsRules: {},
linterOptions: {},
rules: {},
rulesDirectory: [],
};
Expand All @@ -32,34 +33,39 @@ describe("Configuration", () => {
assert.deepEqual(extendConfigurationFile(EMPTY_CONFIG, {}), EMPTY_CONFIG);
assert.deepEqual(extendConfigurationFile({}, {
jsRules: { row: "oar" },
linterOptions: {},
rules: { foo: "bar" },
rulesDirectory: "foo",
}), {
jsRules: { row: "oar" },
linterOptions: {},
rules: {foo: "bar"},
rulesDirectory: ["foo"],
});
const actualConfig = extendConfigurationFile({
jsRules: { row: "oar" },
linterOptions: {},
rules: {
a: 1,
b: 1,
},
rulesDirectory: ["foo", "bar"],
}, {
jsRules: { fly: "wings" },
linterOptions: {},
rules: {
b: 1,
b: 2,
c: 3,
},
rulesDirectory: "baz",
});
});
/* tslint:disable:object-literal-sort-keys */
const expectedConfig = {
}), {
jsRules: {
fly: "wings",
row: "oar",
fly: "wings",
},
linterOptions: {},
rules: {
a: 1,
b: 2,
Expand Down Expand Up @@ -88,13 +94,13 @@ describe("Configuration", () => {
/* tslint:disable:object-literal-sort-keys */
assert.deepEqual(config.jsRules, {
"rule-one": true,
"rule-two": true,
"rule-three": false,
"rule-two": true,
});
assert.deepEqual(config.rules, {
"rule-one": true,
"rule-two": true,
"rule-three": false,
"rule-two": true,
});
/* tslint:enable:object-literal-sort-keys */
});
Expand Down
27 changes: 27 additions & 0 deletions test/files/custom-rules/ruleTwoRule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var Lint = require("tslint/lib/lint");
var Rule = (function (_super) {
__extends(Rule, _super);
function Rule() {
_super.apply(this, arguments);
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new RuleTwoWalker(sourceFile, this.getOptions()));
};
return Rule;
})(Lint.Rules.AbstractRule);
exports.Rule = Rule;
var RuleTwoWalker = (function (_super) {
__extends(RuleTwoWalker, _super);
function RuleTwoWalker() {
_super.apply(this, arguments);
}
RuleTwoWalker.prototype.visitSourceFile = function (node) {
// do nothing
};
return RuleTwoWalker;
})(Lint.RuleWalker);

0 comments on commit dfc718d

Please sign in to comment.