Skip to content

Commit af44074

Browse files
committed
Merge pull request palantir#178 from am11/master
Config: Findup should start from input file dir
2 parents 3ec9788 + 7c26712 commit af44074

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/configuration.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ module Lint.Configuration {
2121

2222
var CONFIG_FILENAME = "tslint.json";
2323

24-
export function findConfiguration(configFile: string): any {
24+
export function findConfiguration(configFile: string, inputFileLocation: string): any {
2525
if (configFile) {
2626
return JSON.parse(fs.readFileSync(configFile, "utf8"));
2727
}
2828

29-
// First look for package.json
30-
configFile = findup("package.json", { nocase: true });
29+
// First look for package.json from input file location
30+
configFile = findup("package.json", { cwd: inputFileLocation, nocase: true });
3131

3232
if (configFile) {
3333
var content = require(configFile);
@@ -46,7 +46,7 @@ module Lint.Configuration {
4646

4747
var defaultPath = path.join(homeDir, CONFIG_FILENAME);
4848

49-
configFile = findup(CONFIG_FILENAME, { nocase: true }) || defaultPath;
49+
configFile = findup(CONFIG_FILENAME, { cwd: inputFileLocation, nocase: true }) || defaultPath;
5050

5151
return configFile ? JSON.parse(fs.readFileSync(configFile, "utf8")) : undefined;
5252
}

src/tslint-cli.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -136,26 +136,27 @@ if ("help" in argv) {
136136
process.exit(0);
137137
}
138138

139-
var configuration = Lint.Configuration.findConfiguration(argv.c);
140-
if (configuration === undefined) {
141-
console.error("unable to find tslint configuration");
142-
process.exit(1);
143-
}
144-
145139
if (!fs.existsSync(argv.f)) {
146140
console.error("Unable to open file: " + argv.f);
147141
process.exit(1);
148142
}
149143

150144
var processFile = (file: string) => {
151145
var contents = fs.readFileSync(file, "utf8");
146+
var configuration = Lint.Configuration.findConfiguration(argv.c, file);
147+
148+
if (configuration === undefined) {
149+
console.error("unable to find tslint configuration");
150+
process.exit(1);
151+
}
152152

153153
var linter = new Lint.Linter(file, contents, {
154154
configuration: configuration,
155155
formatter: argv.t,
156156
rulesDirectory: argv.r,
157157
formattersDirectory: argv.s
158158
});
159+
159160
var lintResult = linter.lint();
160161

161162
if (lintResult.failureCount > 0) {

0 commit comments

Comments
 (0)