PY-10182 Pass --hang-closing to pycodestyle.py if it's enabled in settings

This commit is contained in:
Mikhail Golubev
2017-01-13 11:58:33 +03:00
parent e5cd4ab83f
commit ad6582b62e
@@ -125,14 +125,16 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
private final HighlightDisplayLevel level;
private final List<String> ignoredErrors;
private final int margin;
private final boolean hangClosingBrackets;
public State(String interpreterPath, String fileText, HighlightDisplayLevel level,
List<String> ignoredErrors, int margin) {
List<String> ignoredErrors, int margin, boolean hangClosingBrackets) {
this.interpreterPath = interpreterPath;
this.fileText = fileText;
this.level = level;
this.ignoredErrors = ignoredErrors;
this.margin = margin;
this.hangClosingBrackets = hangClosingBrackets;
}
}
@@ -179,20 +181,22 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
return null;
}
final PyPep8Inspection inspection = (PyPep8Inspection)profile.getUnwrappedTool(PyPep8Inspection.KEY.toString(), file);
final CodeStyleSettings currentSettings = CodeStyleSettingsManager.getInstance(file.getProject()).getCurrentSettings();
final CodeStyleSettings commonSettings = CodeStyleSettingsManager.getInstance(file.getProject()).getCurrentSettings();
final PyCodeStyleSettings customSettings = commonSettings.getCustomSettings(PyCodeStyleSettings.class);
final List<String> ignoredErrors = Lists.newArrayList(inspection.ignoredErrors);
if (!currentSettings.getCustomSettings(PyCodeStyleSettings.class).SPACE_AFTER_NUMBER_SIGN) {
if (!customSettings.SPACE_AFTER_NUMBER_SIGN) {
ignoredErrors.add("E262"); // Block comment should start with a space
ignoredErrors.add("E265"); // Inline comment should start with a space
}
if (!currentSettings.getCustomSettings(PyCodeStyleSettings.class).SPACE_BEFORE_NUMBER_SIGN) {
if (!customSettings.SPACE_BEFORE_NUMBER_SIGN) {
ignoredErrors.add("E261"); // At least two spaces before inline comment
}
final int margin = currentSettings.getRightMargin(file.getLanguage());
return new State(homePath, file.getText(), profile.getErrorLevel(key, file), ignoredErrors, margin);
final int margin = commonSettings.getRightMargin(file.getLanguage());
return new State(homePath, file.getText(), profile.getErrorLevel(key, file),
ignoredErrors, margin, customSettings.HANG_CLOSING_BRACKETS);
}
private static void reportMissingInterpreter() {
@@ -214,6 +218,9 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
if (!collectedInfo.ignoredErrors.isEmpty()) {
options.add("--ignore=" + DEFAULT_IGNORED_ERRORS + "," + StringUtil.join(collectedInfo.ignoredErrors, ","));
}
if (collectedInfo.hangClosingBrackets) {
options.add("--hang-closing");
}
options.add("--max-line-length=" + collectedInfo.margin);
options.add("-");