GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [apex] New rule: field declarations should be at start by gwilymatgearset · Pull Request #2396 · pmd/pmd

Conversation

@gwilymatgearset

@gwilymatgearset gwilymatgearset commented Apr 1, 2020

Copy link
Copy Markdown
Collaborator

Before submitting a PR, please check that:

  • The PR is submitted against master. The PMD team will merge back to support branches as needed.
  • ./mvnw clean verify passes. This will build and test PMD, execute PMD and checkstyle rules. Check this for more info

PR Description:

A rule discussed in #2322 was field declarations should be at the start of a class. This adds that rule.

I first tried to implement this using an xpath rule, but unfortunately the apex parser seems to always put all the field definitions first in the AST, so I had to resort to using line number information and writing the rule in java.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rsoesemann reacted with hooray emoji
All reactions
  • 🎉 1 reaction
gwilymatgearset added 4 commits April 1, 2020 11:24
@gwilymatgearset
Add basic implmentation of FieldDeclarationsShouldBeAtStart for apex
8acb638
@gwilymatgearset
Add rule definition in codestyle.xml
1d62a1f
@gwilymatgearset
Add tests for apex field declarations should be at start
3f0dc27
@gwilymatgearset
Inculde field name in violation message
504cf44
@ghost

ghost commented Apr 1, 2020

Copy link
Copy Markdown
1 Message
📖 No java rules are changed!

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

oowekyala
oowekyala reviewed Apr 2, 2020
View reviewed changes

@oowekyala oowekyala left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for taking this on. I think the rule could be improved a bit. I hope my comments show up in the right order

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread .../java/net/sourceforge/pmd/lang/apex/rule/codestyle/FieldDeclarationsShouldBeAtStartRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread .../java/net/sourceforge/pmd/lang/apex/rule/codestyle/FieldDeclarationsShouldBeAtStartRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread .../java/net/sourceforge/pmd/lang/apex/rule/codestyle/FieldDeclarationsShouldBeAtStartRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread .../java/net/sourceforge/pmd/lang/apex/rule/codestyle/FieldDeclarationsShouldBeAtStartRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread .../java/net/sourceforge/pmd/lang/apex/rule/codestyle/FieldDeclarationsShouldBeAtStartRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread .../java/net/sourceforge/pmd/lang/apex/rule/codestyle/FieldDeclarationsShouldBeAtStartRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Apr 3, 2020
@adangel adangel changed the title [apex] field declarations should be at start [apex] New rule: field declarations should be at start Apr 3, 2020
adangel
adangel reviewed Apr 3, 2020
View reviewed changes
Comment thread pmd-apex/src/main/resources/category/apex/codestyle.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added this to the 6.23.0 milestone Apr 3, 2020
gwilymatgearset added 12 commits April 3, 2020 13:38
@gwilymatgearset
Massively simplify rule with custom comparator
9c13702
@gwilymatgearset
Fix field declaration location rule around nested classes
eb8e7ea
@gwilymatgearset
Also produce errors in inner classes
1359c88
@gwilymatgearset
Correctly detect fields after inner classes
5d1ffa5
@gwilymatgearset
Correctly detect properties before fields
eeac579
@gwilymatgearset
Correctly detect that fields should go before block statements
292bcbb
@gwilymatgearset
Correctly detect fields that appear after static initialization blocks
9e07836
@gwilymatgearset
Fix checkstyle violations
4aae0e2
@gwilymatgearset
Make comment clearer
1331eec
@gwilymatgearset
Extract constant
58185fc
@gwilymatgearset
Make rule a RuleChain
e94db8b
@gwilymatgearset
Should be 6.23.0 for release
6a70bda
@gwilymatgearset

gwilymatgearset commented Apr 3, 2020

Copy link
Copy Markdown
Collaborator Author

Thanks @oowekyala for your comments 😄. They were really helpful for teaching me a bit about java comparators (and it makes the API look less crazy to me now 😛). Also, your comments on the inner classes made me realise there were other things that I was missing (like properties and initializers). So I've added support for those too.

Let me know if you have any other comments :).

oowekyala reacted with thumbs up emoji rsoesemann reacted with laugh emoji
All reactions
  • 👍 1 reaction
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rsoesemann

rsoesemann commented Apr 3, 2020

Copy link
Copy Markdown
Member

@gwilymatgearset No objection to approve and merge that cool rule after you fixed all the issues mentioned by @oowekyala .

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

adangel
adangel approved these changes Apr 4, 2020
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good, thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-apex/src/main/resources/category/apex/codestyle.xml
</example>
</rule>

<rule name="FieldDeclarationsShouldBeAtStart"

@adangel adangel Apr 4, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'll move that up when merging so that the rules are sorted alphabetically. This helps to keep the files organized.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gwilymatgearset reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@adangel adangel self-assigned this Apr 4, 2020
adangel added a commit that referenced this pull request Apr 4, 2020
@adangel
[doc] Update release notes, refs #2396
92a518c
adangel added a commit that referenced this pull request Apr 4, 2020
@adangel
Merge branch 'pr-2396'
6196da4
[apex] New rule: field declarations should be at start #2396
@adangel
adangel merged commit 6a70bda into pmd:master Apr 4, 2020
@gwilymatgearset
gwilymatgearset deleted the apex-field-declarations-should-be-at-start branch April 6, 2020 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@oowekyala oowekyala oowekyala left review comments
@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

a:new-rule Proposal to add a new built-in rule

Projects

None yet

Milestone

6.23.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@gwilymatgearset @rsoesemann @adangel @oowekyala
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.