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

Commit

Permalink
Fixes not a directory error (#2813)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchen63 committed May 23, 2017
1 parent 544393f commit faaee39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/configuration.ts
Expand Up @@ -86,19 +86,19 @@ const BUILT_IN_CONFIG = /^tslint:(.*)$/;
/**
* Searches for a TSLint configuration and returns the data from the config.
* @param configFile A path to a config file, this can be null if the location of a config is not known
* @param inputFileLocation A path to the current file being linted. This is the starting location
* @param inputFilePath A path containing the current file being linted. This is the starting location
* of the search for a configuration.
* @returns Load status for a TSLint configuration object
*/
export function findConfiguration(configFile: string | null, inputFilePath: string): IConfigurationLoadResult {
const path = findConfigurationPath(configFile, inputFilePath);
const loadResult: IConfigurationLoadResult = { path };
const configPath = findConfigurationPath(configFile, inputFilePath);
const loadResult: IConfigurationLoadResult = { path: configPath };

try {
loadResult.results = loadConfigurationFromPath(path);
loadResult.results = loadConfigurationFromPath(configPath);
return loadResult;
} catch (error) {
throw new FatalError(`Failed to load ${path}: ${(error as Error).message}`, error as Error);
throw new FatalError(`Failed to load ${configPath}: ${(error as Error).message}`, error as Error);
}
}

Expand All @@ -120,6 +120,21 @@ export function findConfigurationPath(suppliedConfigFilePath: string | null, inp
return path.resolve(suppliedConfigFilePath);
}
} else {
// convert to dir if it's a file or doesn't exist
let useDirName = false;
try {
const stats = fs.statSync(inputFilePath);
if (stats.isFile()) {
useDirName = true;
}
} catch (e) {
// throws if file doesn't exist
useDirName = true;
}
if (useDirName) {
inputFilePath = path.dirname(inputFilePath);
}

// search for tslint.json from input file location
let configFilePath = findup(CONFIG_FILENAME, inputFilePath);
if (configFilePath !== undefined) {
Expand Down
6 changes: 6 additions & 0 deletions test/configurationTests.ts
Expand Up @@ -209,6 +209,12 @@ describe("Configuration", () => {
findConfigurationPath(null, "./test/files/config-findup"),
path.resolve("./test/files/config-findup/tslint.json"),
);

// gulp-tslint uses a path including the filename
assert.strictEqual(
findConfigurationPath(null, "./test/files/config-findup/somefilename.ts"),
path.resolve("./test/files/config-findup/tslint.json"),
);
});
});

Expand Down

0 comments on commit faaee39

Please sign in to comment.