From 2b4775e237fa3bf434c026c078e7ad7cafbc6416 Mon Sep 17 00:00:00 2001 From: denuno Date: Sun, 11 Aug 2024 19:34:47 -0600 Subject: [PATCH 1/2] add test with empty rule set and test for ignore:line fix this add the current source and a check for an ignore line where a bug is found eventually we should maybe add the option of outputting the whole line in question so this is a start toward that closes #741 --- src/main/java/com/cflint/CFLint.java | 18 +++++++++ src/test/java/com/cflint/TestIgnoreLine.java | 37 +++++++++++++++++++ .../com/cflint/tests/IgnoresAll/.cflintrc | 6 +++ .../com/cflint/tests/IgnoresAll/ignoreAll.cfc | 7 ++++ .../tests/IgnoresAll/ignoreAll.expected.txt | 11 ++++++ .../cflint/tests/IgnoresAll/ignoreLines.cfc | 7 ++++ .../tests/IgnoresAll/ignoreLines.expected.txt | 11 ++++++ 7 files changed, 97 insertions(+) create mode 100644 src/test/java/com/cflint/TestIgnoreLine.java create mode 100644 src/test/resources/com/cflint/tests/IgnoresAll/.cflintrc create mode 100644 src/test/resources/com/cflint/tests/IgnoresAll/ignoreAll.cfc create mode 100644 src/test/resources/com/cflint/tests/IgnoresAll/ignoreAll.expected.txt create mode 100644 src/test/resources/com/cflint/tests/IgnoresAll/ignoreLines.cfc create mode 100644 src/test/resources/com/cflint/tests/IgnoresAll/ignoreLines.expected.txt diff --git a/src/main/java/com/cflint/CFLint.java b/src/main/java/com/cflint/CFLint.java index 6fe266f99..f8ba82de5 100644 --- a/src/main/java/com/cflint/CFLint.java +++ b/src/main/java/com/cflint/CFLint.java @@ -107,6 +107,7 @@ public class CFLint implements IErrorReporter { private static final String MISSING_SEMI = "MISSING_SEMI"; private static final String AVOID_EMPTY_FILES = "AVOID_EMPTY_FILES"; private static final String RESOURCE_BUNDLE_NAME = "com.cflint.cflint"; + private static final Pattern IGNORE_LINE_PATTERN = Pattern.compile("(?i).*cflint\\s+ignore:\\s*line.*"); private CFMLTagInfo tagInfo; private CFMLParser cfmlParser = new CFMLParser(); @@ -130,11 +131,14 @@ public class CFLint implements IErrorReporter { private Element currentElement = null; private boolean strictInclude; private Set> processed = new HashSet<>(); + private String currentSource = ""; + // Stack to store include file depth to ensure no recursion private final Stack includeFileStack = new Stack<>(); private int[] lineOffsets; + public CFLint(final CFLintConfiguration configFile) throws IOException { final CFLintFilter filter = CFLintFilter.createFilter(verbose); bugs = new BugList(filter); @@ -325,6 +329,7 @@ public void process(final String src, final String filename) throws CFLintScanEx final Context context = new Context(filename, null, null, false, handler,configuration); reportRule(null, null, context, null, new ContextMessage(AVOID_EMPTY_FILES, null)); } else { + currentSource = src; lineOffsets = getLineOffsets(src.split("\n")); final CFMLSource cfmlSource = new CFMLSource(src.contains("