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

Fixes not a directory error #2813

Merged
merged 1 commit into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/configuration.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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