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

Update doc for ParameterAssignment #7655

Closed
strkkk opened this issue Feb 25, 2020 · 7 comments · Fixed by #9321
Closed

Update doc for ParameterAssignment #7655

strkkk opened this issue Feb 25, 2020 · 7 comments · Fixed by #9321

Comments

@strkkk
Copy link
Member

strkkk commented Feb 25, 2020

https://checkstyle.org/config_coding.html#ParameterAssignment

Add example for each existing config to show what code is ok and what code cause violation.
Good example is https://checkstyle.org/config_naming.html#AbstractClassName
Look at referenced commits of #5832, to see what and how should be changed in code.

Please play with module/check by means of https://checkstyle.org/cmdline.html to understand how it works.


PLEASE READ https://github.com/checkstyle/checkstyle/wiki/Good-practice-on-how-to-update-examples

@ek08
Copy link
Contributor

ek08 commented Nov 23, 2020

I am on it

@ek08
Copy link
Contributor

ek08 commented Nov 23, 2020

$ cat config.xml

<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="severity" value="error"/>
    <module name="TreeWalker">
		<module name="ParameterAssignment"/>
    </module>
</module>

$ cat MyClass.java

class MyClass {
  int method1(int parameter1, int parameter2) {
    if (parameter2 > 50) {
      parameter1 -= 2;  // violation, Parameter assignment is poor programming practice
    }
    return parameter1;
  }
}

$ java -jar "-Duser.language=en -Duser.country=US" checkstyle-8.37-all.jar -c config.xml MyClass.java
Starting audit...
[ERROR] /home/ehtesham/MyClass.java:4:18: Assignment of parameter 'parameter1' is not allowed. [ParameterAssignment]
Audit done.
Checkstyle ends with 1 errors.

$ cat MyClass.java

class MyClass {
  int method2(int parameter1, int parameter2) {
    int local = parameter1;
    if (parameter2 > 50) {
      local -= 2;  // OK, since a local variable is assigned
    }
    return local;
  }
}

$ java -jar "-Duser.language=en -Duser.country=US" checkstyle-8.37-all.jar -c config.xml MyClass.java
Starting audit...
Audit done.

ek08 added a commit to ek08/checkstyle that referenced this issue Nov 23, 2020
ek08 added a commit to ek08/checkstyle that referenced this issue Nov 23, 2020
ek08 added a commit to ek08/checkstyle that referenced this issue Nov 23, 2020
github-actions bot pushed a commit to ek08/checkstyle that referenced this issue Nov 24, 2020
ek08 added a commit to ek08/checkstyle that referenced this issue Nov 25, 2020
github-actions bot pushed a commit to ek08/checkstyle that referenced this issue Nov 30, 2020
@abhijeet007rocks8
Copy link

Can i work on it??

@romani
Copy link
Member

romani commented Feb 22, 2021

@abhijeet007rocks8 , all approved issues are waiting for contributors.
just make a comment "I am on it" and send PR ...

@romani
Copy link
Member

romani commented Feb 22, 2021

@abhijeet007rocks8 , you can reuse work at #9013 , it looks like abandoned PR.

@ek08, last notification .

@AkMo3
Copy link
Contributor

AkMo3 commented Feb 23, 2021

I am on it. Sorry @abhijeet007rocks8 I didn't see that earlier. Please take any other issue.

AkMo3 added a commit to AkMo3/checkstyle that referenced this issue Feb 24, 2021
@checkstyle checkstyle deleted a comment from sudo-karx Feb 24, 2021
AkMo3 added a commit to AkMo3/checkstyle that referenced this issue Feb 24, 2021
AkMo3 added a commit to AkMo3/checkstyle that referenced this issue Feb 24, 2021
AkMo3 added a commit to AkMo3/checkstyle that referenced this issue Feb 24, 2021
@rnveach
Copy link
Member

rnveach commented Feb 26, 2021

Fix was merged

@rnveach rnveach added this to the 8.41 milestone Feb 26, 2021
SGanguly1999 pushed a commit to SGanguly1999/checkstyle that referenced this issue Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants