diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/codestyle/AvoidTabCharacterRule.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/codestyle/AvoidTabCharacterRule.java new file mode 100644 index 0000000000..68c1b7f9de --- /dev/null +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/codestyle/AvoidTabCharacterRule.java @@ -0,0 +1,38 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.plsql.rule.codestyle; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; + +import net.sourceforge.pmd.lang.plsql.ast.ASTInput; +import net.sourceforge.pmd.lang.plsql.rule.AbstractPLSQLRule; + +public class AvoidTabCharacterRule extends AbstractPLSQLRule { + + public AvoidTabCharacterRule() { + addRuleChainVisit(ASTInput.class); + } + + @Override + public Object visit(ASTInput node, Object data) { + try (BufferedReader in = new BufferedReader(new StringReader(node.getSourcecode()))) { + String line; + int lineNumber = 0; + while ((line = in.readLine()) != null) { + lineNumber++; + if (line.indexOf('\t') != -1) { + addViolationWithMessage(data, null, "Tab characters are not allowed. Use spaces for intendation", + lineNumber, lineNumber); + break; + } + } + } catch (IOException e) { + throw new RuntimeException("Error while executing rule AvoidTabCharacter", e); + } + return data; + } +} diff --git a/pmd-plsql/src/main/resources/category/plsql/codestyle.xml b/pmd-plsql/src/main/resources/category/plsql/codestyle.xml index 719f2c59fe..a906202b02 100644 --- a/pmd-plsql/src/main/resources/category/plsql/codestyle.xml +++ b/pmd-plsql/src/main/resources/category/plsql/codestyle.xml @@ -9,6 +9,24 @@ Rules which enforce a specific coding style. + + +This rule checks, that there are no tab characters (`\t`) in the source file. +It reports only the first occurrence per file. + +Using tab characters for indentation is not recommended, since this requires that every developer +uses the same tab with in their editor. + +This rule is the PMD equivalent of checkstyle's [FileTabCharacter](http://checkstyle.sourceforge.net/config_whitespace.html#FileTabCharacter) check. + + 3 + + + + + + Using tabs - only the first tab character is reported + 1 + 2 + + plsql + + + + No tabs + 0 + + plsql + + \ No newline at end of file