private void checkRegularExpression() { if (searchPattern == null) { try { searchPattern = Pattern.compile(headerFormat, Pattern.DOTALL); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("[" + getClass().getSimpleName() + "] Unable to compile the regular expression: " + headerFormat, e); } } String fileContent; try { fileContent = getContext().getJavaScriptFile().contents(); } catch (IOException e) { throw new IllegalStateException("Unable to read file " + getContext().getJavaScriptFile().toString(), e); } Matcher matcher = searchPattern.matcher(fileContent); if (!matcher.find() || matcher.start() != 0) { addIssue(new FileIssue(this, MESSAGE)); } }
@Override public void leaveFile(Tree scriptTree) { if (isOnlyExport && nameOfExported != null) { String fileName = getContext().getJavaScriptFile().fileName().split("\\.")[0]; if (!"index".equals(fileName) && !sameName(nameOfExported, fileName)) { addIssue(new FileIssue(this, String.format(MESSAGE, nameOfExported))); } } isOnlyExport = true; nameOfExported = null; }
private void checkPlainText() { if (expectedLines == null) { expectedLines = headerFormat.split("(?:\r)?\n|\r"); } JavaScriptFile file = getContext().getJavaScriptFile(); List<String> lines = CheckUtils.readLines(file); if (!matches(expectedLines, lines)) { addIssue(new FileIssue(this, MESSAGE)); } }
@Override public void visitNode(Tree tree) { if (!((InternalSyntaxToken) tree).isEOF()) { return; } SyntaxToken token = (SyntaxToken) tree; int lines = token.line(); if (lines > maximum) { String fileName = getContext().getJavaScriptFile().fileName(); addIssue(new FileIssue(this, String.format(MESSAGE, fileName, lines, maximum))); } }
@Override public void visitScript(ScriptTree tree) { if (tree.items() != null) { int lastLine = tree.EOFToken().line(); int lastTokenLine = tree.items().lastToken().endLine(); if (lastLine == lastTokenLine) { addIssue(new FileIssue(this, MESSAGE)); } } }