问题
My team is refactoring our codebase, and we're using ESLint to identify the files with any lint errors. We currently have one .eslintrc file with extremely high thresholds, and are ratcheting these thresholds down as we make improvements to certain files in the codebase. For example, our "max-statements" threshold is set to 99 statements, and our target is to get this down to 20 statements. So we incrementally lower our threshold from 99 to 98 to 97 etc., until we see a lint error appear. We then know which file to refactor next.
The problem is that this strategy doesn't stop the bleeding. To continue the above example, let's say a new controller is introduced which has 45 statements. This number is lower than our current threshold (because our bottleneck file has 99 statements), but higher than our target threshold of 20 statements.
Ideally, we'd like to see errors for any lint errors which violate our current thresholds, and warnings for lint errors which violate our target thresholds. This would give us a list of all offending files and triage the ones with the most egregious violations first. For example:
// inside .eslintrc
....
"rules": {
"max-statements": [2, 99],
"max-statements": [1, 20]
}
....
In this case, we'd see warnings for any files with more than 20 statements, and errors for every file with more than 99 statements.
I tried implementing the above configuration, but as I feared, the 1st "max-statements" rule was overridden by the 2nd.
Is there any way to achieve what I described?
回答1:
When running ESlint from command line, you can specify the configuration file. Just call the command twice with different configurations.
You can actually parse the result from the first run and ignore files with errors in the second run, if needed.
来源:https://stackoverflow.com/questions/34077756/including-both-errors-and-warnings-for-same-eslint-rule