Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regexp: violation pointing to line 0 while other Checks count first line as 1 #14064

Closed
romani opened this issue Nov 25, 2023 · 1 comment · Fixed by #14057
Closed

Regexp: violation pointing to line 0 while other Checks count first line as 1 #14064

romani opened this issue Nov 25, 2023 · 1 comment · Fixed by #14057

Comments

@romani
Copy link
Member

romani commented Nov 25, 2023

https://checkstyle.org/checks/regexp/regexp.html#Regexp

problem is detected at #14057 and blocks it as test suite can not accept line 0 as expected.

$ cat config.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
  <module name="TreeWalker">
    <module name="Regexp">
      <property name="format" value="// This code is copyrighted"/>
    </module>
  </module>
</module>

$ cat Test.java 
// comment
public class TestClass {
}

$ java -jar checkstyle-10.12.4-all.jar -c config.xml Test.java
Starting audit...
[ERROR] /var/tmp/Test.java:0: Required pattern '// This code is copyrighted' missing in file. [Regexp]
Audit done.
Checkstyle ends with 1 errors.

example for other Check that shows that line number is 1

$ cat config.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
      <module name="FileLength">
        <property name="max" value="1"/>
      </module>
</module>

$ cat Test.java 
// comment
public class TestClass {
}

$ java -jar checkstyle-10.12.4-all.jar -c config.xml Test.java
Starting audit...
[ERROR] /var/tmp/Test.java:1: File length is 3 lines (max allowed is 1). [FileLength]
Audit done.
Checkstyle ends with 1 errors.

prove in code that line length starts from 1:

// now we have lineNo and columnNo, both starting at zero.
return new LineColumn(lineNo + 1, columnNo);

Expected:
[ERROR] /var/tmp/Test.java:1: Required pattern '// This code is copyrighted' missing in file. [Regexp]

@romani
Copy link
Member Author

romani commented Nov 26, 2023

I think it should be "bug" and we consider "breaking compatibility" for config in most cases, this is change in behavior.

romani pushed a commit to suniti0804/checkstyle that referenced this issue Nov 26, 2023
romani pushed a commit to suniti0804/checkstyle that referenced this issue Nov 30, 2023
suniti0804 added a commit to suniti0804/checkstyle that referenced this issue Dec 2, 2023
suniti0804 added a commit to suniti0804/checkstyle that referenced this issue Dec 4, 2023
@github-actions github-actions bot added this to the 10.12.6 milestone Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants