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

Commit

Permalink
Remove underscore dependency; use own camelize
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-hanson committed Jan 5, 2017
1 parent 7c73890 commit ba5787c
Showing 8 changed files with 16 additions and 14 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@
"glob": "^7.1.1",
"optimist": "~0.6.0",
"resolve": "^1.1.7",
"underscore.string": "^3.3.4",
"update-notifier": "^1.0.2"
},
"peerDependencies": {
@@ -60,8 +59,6 @@
"@types/node": "^6.0.56",
"@types/optimist": "0.0.29",
"@types/resolve": "0.0.4",
"@types/underscore": "^1.7.36",
"@types/underscore.string": "0.0.30",
"chai": "^3.5.0",
"js-yaml": "^3.7.0",
"mocha": "^3.2.0",
2 changes: 1 addition & 1 deletion scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -7,6 +7,6 @@
"noUnusedLocals": true,
"sourceMap": true,
"target": "es5",
"lib": ["es6", "dom"]
"lib": ["es6"]
}
}
2 changes: 1 addition & 1 deletion src/formatterLoader.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@

import * as fs from "fs";
import * as path from "path";
import {camelize} from "underscore.string";
import { camelize } from "./utils";

const moduleDirectory = path.dirname(module.filename);
const CORE_FORMATTERS_DIRECTORY = path.resolve(moduleDirectory, ".", "formatters");
6 changes: 2 additions & 4 deletions src/formatters/msbuildFormatter.ts
Original file line number Diff line number Diff line change
@@ -15,20 +15,18 @@
* limitations under the License.
*/

import {camelize} from "underscore.string";

import {AbstractFormatter} from "../language/formatter/abstractFormatter";
import {IFormatterMetadata} from "../language/formatter/formatter";
import {RuleFailure} from "../language/rule/rule";

import * as Utils from "../utils";
import {camelize, dedent} from "../utils";

export class Formatter extends AbstractFormatter {
/* tslint:disable:object-literal-sort-keys */
public static metadata: IFormatterMetadata = {
formatterName: "msbuild",
description: "Formats errors for consumption by msbuild.",
descriptionDetails: Utils.dedent`
descriptionDetails: dedent`
The output is compatible with both msbuild and Visual Studio. All failures have the
'warning' severity.`,
sample: "myFile.ts(1,14): warning: Missing semicolon",
5 changes: 2 additions & 3 deletions src/ruleLoader.ts
Original file line number Diff line number Diff line change
@@ -17,11 +17,10 @@

import * as fs from "fs";
import * as path from "path";
import {camelize} from "underscore.string";

import {getRulesDirectories} from "./configuration";
import {IDisabledInterval, IRule} from "./language/rule/rule";
import {dedent} from "./utils";
import {camelize, dedent} from "./utils";

const moduleDirectory = path.dirname(module.filename);
const CORE_RULES_DIRECTORY = path.resolve(moduleDirectory, ".", "rules");
@@ -151,7 +150,7 @@ function buildDisabledIntervalsFromSwitches(ruleSpecificList: IEnableDisablePosi
while (i < ruleSpecificList.length) {
const startPosition = ruleSpecificList[i].position;

// rule enabled state is always alternating therefore we can use position of next switch as end of disabled interval
// rule enabled state is always alternating therefore we can use position of next switch as end of disabled interval
// set endPosition as Infinity in case when last switch for rule in a file is disabled
const endPosition = ruleSpecificList[i + 1] ? ruleSpecificList[i + 1].position : Infinity;

2 changes: 1 addition & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
"declaration": true,
"sourceMap": false,
"target": "es5",
"lib": ["es6", "dom"],
"lib": ["es6"],
"outDir": "../lib"
}
}
8 changes: 8 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -39,6 +39,14 @@ export function objectify(arg: any): any {
}
}

/**
* Replace hyphens in a rule name by upper-casing the letter after them.
* E.g. "foo-bar" -> "fooBar"
*/
export function camelize(stringWithHyphens: string): string {
return stringWithHyphens.replace(/-(.)/g, (_, nextLetter) => nextLetter.toUpperCase());
}

/**
* Removes leading indents from a template string without removing all leading whitespace
*/
2 changes: 1 addition & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
"strictNullChecks": true,
"sourceMap": true,
"target": "es5",
"lib": ["es6", "dom"],
"lib": ["es6"],
"outDir": "../build"
},
"include": [

0 comments on commit ba5787c

Please sign in to comment.