-
Notifications
You must be signed in to change notification settings - Fork 885
Override defaultSeverity defined in extended configs #3449
Changes from 3 commits
251640b
97dbcf8
7dd26fc
f9a9b93
75587bd
aa11a2e
58497de
04cb64e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ import { arrayify, hasOwnProperty, stripComments } from "./utils"; | |
|
||
export interface IConfigurationFile { | ||
/** | ||
* The severity that is applied to rules in _this_ config with `severity === "default"`. | ||
* The severity that is applied to rules in this and _extended_ configs with `severity === "default"`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should probably be more verbose: |
||
* Not inherited. | ||
*/ | ||
defaultSeverity?: RuleSeverity; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this property declared on this interface? It's no longer of any use once the config is parsed. It's also never set by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is used on lines 70 and 78:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I know. But the value is never read. In addition While you are already touching this code, can you please add |
||
|
@@ -200,9 +200,10 @@ function findup(filename: string, directory: string): string | undefined { | |
* 'path/to/config' will attempt to load a to/config file inside a node module named path | ||
* @param configFilePath The configuration to load | ||
* @param originalFilePath The entry point configuration file | ||
* @param extendingConfig The configuration which extends this one | ||
* @returns a configuration object for TSLint loaded from the file at configFilePath | ||
*/ | ||
export function loadConfigurationFromPath(configFilePath?: string, originalFilePath = configFilePath) { | ||
export function loadConfigurationFromPath(configFilePath?: string, originalFilePath = configFilePath, extendingConfig?: RawConfigFile) { | ||
if (configFilePath == undefined) { | ||
return DEFAULT_CONFIG; | ||
} else { | ||
|
@@ -224,14 +225,19 @@ export function loadConfigurationFromPath(configFilePath?: string, originalFileP | |
delete (require.cache as { [key: string]: any })[resolvedConfigFilePath]; | ||
} | ||
|
||
// defaultSeverity defined in the config which extends this one wins. | ||
if (extendingConfig !== undefined && extendingConfig.defaultSeverity !== undefined) { | ||
rawConfigFile.defaultSeverity = extendingConfig.defaultSeverity; | ||
} | ||
|
||
const configFileDir = path.dirname(resolvedConfigFilePath); | ||
const configFile = parseConfigFile(rawConfigFile, configFileDir); | ||
|
||
// load configurations, in order, using their identifiers or relative paths | ||
// apply the current configuration last by placing it last in this array | ||
const configs: IConfigurationFile[] = configFile.extends.map((name) => { | ||
const nextConfigFilePath = resolveConfigurationPath(name, configFileDir); | ||
return loadConfigurationFromPath(nextConfigFilePath, originalFilePath); | ||
return loadConfigurationFromPath(nextConfigFilePath, originalFilePath, rawConfigFile); | ||
}).concat([configFile]); | ||
|
||
return configs.reduce(extendConfigurationFile, EMPTY_CONFIG); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"defaultSeverity": "error", | ||
"rules": { | ||
"default-severity-error": { "severity": "default" } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"default-severity-unspecified": { "severity": "default" } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": [ "./tslint-default-severity-unspecified.json", "./tslint-default-severity-error.json" ], | ||
"defaultSeverity": "warning", | ||
"rules": { | ||
"default-severity-warning": { "severity": "default" } | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add another config that has no defaultSeverity, that extends this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please suggest the name for this file. I could come up only with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just take the name you suggested. I cannot come up with a better one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you copy over the edit I suggested in
configuration.ts
to here? that would make it: