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

Issue #14487: add support to ignore JSNI methods for LineLength check in google config #14501

Closed
wants to merge 1 commit into from

Conversation

Zopsss
Copy link
Contributor

@Zopsss Zopsss commented Feb 18, 2024

Issue #14487

Ignore JSNI methods' length in google config based on 4.4 Column Limit: 100

Exceptions:

  1. Lines where obeying the column limit is not possible (for example, a long URL in Javadoc, or a long JSNI method reference).

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update

<a href="https://webtoolkit.googleblog.com/2008/07/getting-to-really-know-gwt-part-1-jsni.html">
JSNI</a>
could not be detected right now, but might be possible after
comments and javadoc support appear in Checkstyle.

items:

@Zopsss
Copy link
Contributor Author

Zopsss commented Feb 18, 2024

sorry I accidently requested a re-review from you.. I don't have permission to dismiss it

@Zopsss
Copy link
Contributor Author

Zopsss commented Feb 18, 2024

mvn clean verify is giving these errors:

[ERROR] Failures: 
[ERROR]   XdocsPagesTest.testAllCheckSections:579->validateCheckSection:665->validateUsageExample:1545 suppresswithplaintextcommentfilter.xml section 'SuppressWithPlainTextCommentFilter' should have a google section since it is in it's config
expected to be true
[ERROR]   XdocsPagesTest.testAllStyleRules:1672 google_style.xml requires the following check(s) to appear: [SuppressWithPlainTextCommentFilter]
expected to be empty
but was: [SuppressWithPlainTextCommentFilter]

I have added the suppression description in google_style.xml but it is still complaining about it. What do I need to do to fix this?

And also I added following to the suppresswithplaintextcommentfilter.xml in Example of Usage subsection:

<li>
  <a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressWithPlainTextCommentFilter">
  Google Style</a>
</li>

but this gets automatically removed after mvn clean verify

note: the link I specified in href is not working currently as there is no SuppressWithPlainTextCommentFilter in Checkstyle's main branch's google_checks.xml

@Zopsss
Copy link
Contributor Author

Zopsss commented Feb 22, 2024

@romani ping

@nrmancuso
Copy link
Member

suppresswithplaintextcommentfilter.xml

This is generated from the associated template file, please update that.

I have added the suppression description in google_style.xml but it is still complaining about it. What do I need to do to fix this?

Please use git blame to find some commit where we added other filters, there might be some special changes needed for these.

@Zopsss
Copy link
Contributor Author

Zopsss commented Feb 23, 2024

suppresswithplaintextcommentfilter.xml

This is generated from the associated template file, please update that.

I have added the suppression description in google_style.xml but it is still complaining about it. What do I need to do to fix this?

Please use git blame to find some commit where we added other filters, there might be some special changes needed for these.

thanks for the help, I have resolved these errors.

I'm facing some new errors after running mvn clean verify now...

org.apache.maven.project.ProjectBuildingException: Error resolving project artifact: org.eclipse.m2e:lifecycle-mapping:pom:1.0.0 was not found in https://repo.maven.apache.org/mave
n2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced for project org.eclipse.m2e:lifecycle-mapping:pom:1.0.0
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: org.eclipse.m2e:lifecycle-mapping:pom:1.0.0 was not found in https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.12.1:site (default-site) on project checkstyle: Error generating maven-javadoc-plugin:3.6.3:javadoc report: Project contains Javadoc Warnings -> [Help 1]

some warning classes mentioned in the last errors are:

[WARNING] C:\Open Source\checkstyle\src\main\java\com\puppycrawl\tools\checkstyle\gui\BaseCellEditor.java:38: warning: use of default constructor, which does not provide a comment 
[WARNING] public class BaseCellEditor implements CellEditor {
[WARNING] ^
[WARNING] C:\Open Source\checkstyle\src\main\java\com\puppycrawl\tools\checkstyle\filefilters\BeforeExecutionExclusionFileFilter.java:60: warning: use of default constructor, which does not provide a comment

note: It mentioned so many warning classes, I did not add all of them otherwise the comment would be too long... I also tried to run mvn clean site it was also giving me same errors.

I did not touched these classes at all, I think the error is not caused by the changes I made, it is caused by something else... I'm not so sure what to do with these errors.

Can you help me out with this? @nrmancuso

@nrmancuso
Copy link
Member

I did not touched these classes at all, I think the error is not caused by the changes I made, it is caused by something else

You can always check this by checking out master and running mvn clean verify on your local and comparing that to this branch.

@Zopsss
Copy link
Contributor Author

Zopsss commented Feb 24, 2024

You can always check this by checking out master and running mvn clean verify on your local and comparing that to this branch.

IDK how but now mvn clean verify gives BUILD SUCCESS but the mvn clean site is still giving the same warning error in both branches, master and the branch im working on.

@Zopsss
Copy link
Contributor Author

Zopsss commented Feb 26, 2024

You can always check this by checking out master and running mvn clean verify on your local and comparing that to this branch.

IDK how but now mvn clean verify gives BUILD SUCCESS but the mvn clean site is still giving the same warning error in both branches, master and the branch im working on.

@nrmancuso @romani is my PR ready to merged?

@Zopsss
Copy link
Contributor Author

Zopsss commented Feb 27, 2024

@nrmancuso did the git pull and also rebased my branch with master but it is still giving the same error... maybe some merged PR introduced this bug.

and sorry for the late reply, GitHub didn't notified me about the force push

@nrmancuso
Copy link
Member

@Zopsss spellcheck failure is valid, please fix it

@Zopsss
Copy link
Contributor Author

Zopsss commented Feb 28, 2024

@Zopsss spellcheck failure is valid, please fix it

done. I also needed to modify releases.xml as it was giving an error because a line was longer than 100 characters. @nrmancuso

@Zopsss
Copy link
Contributor Author

Zopsss commented Feb 28, 2024

dont know why circleci and semaphoreci are complaining, they didn't specify proper error message ;__;

@nrmancuso
Copy link
Member

@Zopsss please resolve conflicts

@Zopsss
Copy link
Contributor Author

Zopsss commented Feb 29, 2024

@Zopsss please resolve conflicts

Done and now all checks are passing expect the Cirrus @nrmancuso

@Zopsss
Copy link
Contributor Author

Zopsss commented Feb 29, 2024

the website looks fine to me. I guess we're good to go now

@Zopsss
Copy link
Contributor Author

Zopsss commented Mar 2, 2024

@nrmancuso

Copy link
Member

@nrmancuso nrmancuso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Items:

Copy link
Member

@nrmancuso nrmancuso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zopsss thanks a lot, it is always good to see more ✅ on the google config!

@Zopsss
Copy link
Contributor Author

Zopsss commented Mar 8, 2024

@romani ping

@romani
Copy link
Member

romani commented Mar 12, 2024

GitHub, generate website

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok to merge

@romani romani requested a review from rnveach March 12, 2024 04:41
@romani romani assigned rnveach and unassigned romani Mar 12, 2024
@romani
Copy link
Member

romani commented Mar 12, 2024

the only question can be:
Do we need to add SuppressWithPlainTextCommentFilter to table https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/40934dd_2024044506/google_style.html#a4.4 ? as it become very meaningful part of coverage.
Other filters are not added, so it is gray area.

@Zopsss
Copy link
Contributor Author

Zopsss commented Mar 12, 2024

Other filters are not added, so it is gray area.

Umm I'm not so sure about it because there are other Checks too which uses suppressions but we've not added them to the table.

For example,

<module name="SuppressionXpathSingleFilter">

we're using SuppressionXpathSingleFilter for RightCurlyAlone property but we've not added it to the table. Here we're using suppression on a property of the check but in our case we're using the suppression on our whole Check.

Maybe we can add the suppression to the Suppressions section, like I did here #14501 (review), I've removed thay code as Mr Nick suggested but if you agree with me then I can add it again. Again I'm not so sure that we should follow this approach or we should do as you suggested.

@romani
Copy link
Member

romani commented Mar 12, 2024

We can always improve in separate issue. If maintainers find it useful. I am not sure about it.

<!-- See https://google.github.io/styleguide/javaguide.html#s4.4-column-limit -->
<module name="SuppressWithPlainTextCommentFilter">
<property name="offCommentFormat" value="\/\*-\{"/>
<property name="onCommentFormat" value="\}-\*\/"/>
Copy link
Member

@rnveach rnveach Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nrmancuso @romani Why are we ignoring the entire JSNI method?

https://google.github.io/styleguide/javaguide.html#s4.4-column-limit

Lines where obeying the column limit is not possible (for example, ... a long JSNI method reference)

Google seems pretty clear it should only be the method reference, in the issue's case seems to be the method declaration which I am not sure it is a reference, and not the entire method.

The console.log violation in the issue seems valid to me. I am starting to think the other violation is valid.

https://checkstyle.org/google_style.html#a4.4

JSNI could not be detected right now, but might be possible after comments and javadoc support appear in Checkstyle.

We cannot detect JSNI references without parsing support IMO.

Copy link
Member

@rnveach rnveach Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are to ignore JSNI completely because it is not supported by us, then https://checkstyle.org/google_style.html#a4.4 needs to be updated to say that and shouldn't be removed or turned green. The example in the issue doesn't seem to be a valid reason to ignore JSNI. It should be centered around we cannot identify JSNI method references which is what Google says we must be able to identify.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Google seems pretty clear it should only be the method reference

Do you have examples of method reference?
What is this? And how it looks like?

I found https://groups.google.com/g/Google-Web-Toolkit/c/8PXM54IwtDE/m/9naSp1CTYdcJ , so looks like @com.ecopy.gwt.client.Utils::messageBox(Ljava/lang/String;,Ljava/lang/ String;); is a jsni method reference. But I don't know why it can not be wrapped and how it can be used

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It comes down to this: without more details or examples, we really have no idea what the author of the google style guide had in mind when they wrote it. If we want to make sure we are doing the right thing here, we should open an issue at https://github.com/google/styleguide?tab=readme-ov-file for clarification in this section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zopsss , please create issue on Google style to clarify reason of such special allowance for long JSNI method reference as it is wrap-able.

Copy link
Contributor Author

@Zopsss Zopsss Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zopsss your posts are very well written, thanks for that.

Thankk youuuu 😺✨

I am not sure what the lift required is to set up the GWT compiler, but at this point it might be a good idea to do this and see if such references can be line wrapped or not.

Yeahh I don't think many people uses GWT compiler. But it's better to ask the community before moving on

Copy link
Member

@nrmancuso nrmancuso Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear:

but at this point it might be a good idea to do this and see if such references can be line wrapped or not

This means that you might be able to get a definitive answer on the line wrapping without waiting for a reply in your posts.

The style guide makes it sound like it’s not possible to do this, but if it is, then this statement from the style guide is either outdated or plain incorrect.

Copy link
Contributor Author

@Zopsss Zopsss Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that you might be able to get a definitive answer on the line wrapping without waiting for a reply in your posts.

Can you elaborate what do you mean by definitive answer?

The style guide makes it sound like it’s not possible to do this, but if it is, then this statement from the style guide is either outdated or plain incorrect.

The style guide is really old, I guess the documentation is not changed since it was created so it is outdated.

JSNI could not be detected right now, but might be possible after comments and javadoc support appear in Checkstyle

As you can see at the time google_checks.xml was created, Checkstyle did not had support for comments/javadocs.

Support for google java style guide was introduced in 2014. Here's the GSoC project link https://github.com/checkstyle/checkstyle/wiki/Checkstyle-GSoC-2014-Project-Ideas#project-name-checkstyle-configuration-for-googles-java-style-guide

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate...

I am referring to the comment at #14501 (comment), if we are going to spend a bunch of time writing posts and waiting for replies, we can at least learn more about JSNI and see what the hubbub about line wrapping is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh okhay, I would love to do more research on JSNI but my mid-term exams coming and I'm also working on other issues too, it is really difficult to get some time for doing the research stuff. So it would be really helpful if you or other maintainer can find the reason about why there is need to ignore JSNI method for LineLength module. I'm really sorry for asking maintainers to do this. @nrmancuso

@romani
Copy link
Member

romani commented Mar 23, 2024

ok, @Zopsss , we need to move this PR from being stuck.

Please spend some time to get GWT example project to work in any IDE and test yourself if there is problem with line wrap.
https://www.gwtproject.org/
https://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#methods-fields
https://dzone.com/refcardz/gwt-style-configuration-and-js
https://livebook.manning.com/book/gwt-in-action-second-edition/chapter-11/84

please share images, log outputs of errors or no errors.

even we found that wrapping is not problem, it is success, as we can close issue on our issue tracker. And simply state to google style to remove this point about JSNI) or we will suggest to use your config only for people who carers, but looks like nobody care as nobody created issue to do such suppression. But your config will be in our issue as workaround.

@Zopsss
Copy link
Contributor Author

Zopsss commented Mar 23, 2024

ok, @Zopsss , we need to move this PR from being stuck.

Please spend some time to get GWT example project to work in any IDE and test yourself if there is problem with line wrap. https://www.gwtproject.org/ https://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#methods-fields https://dzone.com/refcardz/gwt-style-configuration-and-js https://livebook.manning.com/book/gwt-in-action-second-edition/chapter-11/84

please share images, log outputs of errors or no errors.

even we found that wrapping is not problem, it is success, as we can close issue on our issue tracker. And simply state to google style to remove this point about JSNI) or we will suggest to use your config only for people who carers, but looks like nobody care as nobody created issue to do such suppression. But your config will be in our issue as workaround.

yeah I'll do my research as soon as I get some time.

@romani romani self-requested a review March 24, 2024 15:00
@romani romani removed their assignment Mar 26, 2024
@Zopsss
Copy link
Contributor Author

Zopsss commented May 29, 2024

Back to this PR, so I was trying to setup GWT project to test if JSNI method references are wrap-able or not. But I had a doubt, how are we going to recognize the JSNI method reference?

Here is an example of jsni method reference:

this.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);

how can we recognize it using regex? I guess it is not possible?

The example was taken from official GWT documentation:

https://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html

from Accessing Java fields from JavaScript's example section.

Plus IDEs now does not have support for GWT, it's really difficult to setup project locally and execute it. There are tutorials available on how to setup GWT project but they are mostly 7-8 years old, the setup process mentioned in documentation is also really old and outdated.

Should we close this issue? @romani

@romani
Copy link
Member

romani commented Jun 2, 2024

https://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html

(INFO: For new implementations use the future-proof JsInterop instead. JSNI will be removed with GWT 3.)

image

https://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJsInterop.html

JsInterop is one of the core features of GWT 2.8. As the name suggests, JsInterop is a way of interoperating Java with JavaScript. It offers a better way of communication between the two using annotations instead of having to write JavaScript in your classes (using JSNI). More details about the annotations can be found in GWT javadoc: https://www.gwtproject.org/javadoc/latest/jsinterop/annotations/package-summary.html

@romani
Copy link
Member

romani commented Jun 4, 2024

Ok.

long JSNI method reference

Still present at
https://google.github.io/styleguide/javaguide.html#s4.4-column-limit

I do see clear reason that it is deprecated, so no reason to add support for it.
But we have create special separate issue to explain all details of deprecation.
And our official position to explicitly exclude this request from coverage.
In scope of such new issue we simply update coverage table with note that jsni is not supported and not planned to be supported with link to new issue to read all details.

Please create new issue and let's close this PR and related issue as won't fix

@Zopsss
Copy link
Contributor Author

Zopsss commented Jun 4, 2024

Please create new issue and let's close this PR and related issue as won't fix

Done. New issue: #14938

@Zopsss Zopsss closed this Jun 4, 2024
@Zopsss Zopsss deleted the jsnimethod branch June 5, 2024 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants