Skip to content

Commit

Permalink
Fixes palantir#37 -- don't ignore leading and trailing underscores an…
Browse files Browse the repository at this point in the history
…d dashes
  • Loading branch information
gscshoyru committed Mar 6, 2014
1 parent 17b0837 commit f551da8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Change Log
===

* [bug] the rule loader no longer transforms/ignores the leading and trailing underscores and dashes of rule names in the config file
* [feature] the `check-operator` option for the `whitespace` rule now checks whitespace around the => token
* [bug] `export import` statements no longer false positives for `no-unused-variable-rule`

Expand Down
14 changes: 12 additions & 2 deletions src/ruleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module Lint {
}

export function findRule(name: string, rulesDirectory?: string) {
var camelizedName = _s.camelize(name + "Rule");
var camelizedName = transformName(name);

// first check for core rules
var Rule = loadRule(CORE_RULES_DIRECTORY, camelizedName);
Expand All @@ -74,7 +74,7 @@ module Lint {
var subDirectory = _s.strLeft(rulesDirectory, "-");
var ruleName = _s.strRight(rulesDirectory, "-");
if (subDirectory !== rulesDirectory && ruleName !== rulesDirectory) {
camelizedName = _s.camelize(ruleName + "Rule");
camelizedName = transformName(ruleName);
Rule = loadRule(rulesDirectory, subDirectory, camelizedName);
if (Rule) {
return Rule;
Expand All @@ -85,6 +85,16 @@ module Lint {
return undefined;
}

function transformName(name: string) {
// camelize strips out leading and trailing underscores and dashes, so make sure they aren't passed to camelize
// the regex matches the groups (leading underscores and dashes)(other characters)(trailing underscores and dashes)
var nameMatch = name.match(/^([-_]*)(.*?)([-_]*)$/);
if (nameMatch == null) {
return name + "Rule";
}
return nameMatch[1] + _s.camelize(nameMatch[2]) + nameMatch[3] + "Rule";
}

function loadRule(...paths: string[]) {
var rulePath = paths.reduce((p, c) => path.join(p, c), "");
var fullPath = path.resolve(moduleDirectory, rulePath);
Expand Down

0 comments on commit f551da8

Please sign in to comment.