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

using a codenarc ruleset file seems to fail / groovylintrc is not codenarc compatible #62

Closed
unitysipu opened this issue Jul 2, 2020 · 4 comments · Fixed by #72
Closed

Comments

@unitysipu
Copy link

Codenarc has native gradle-support which makes it simple to integrate into the build, npm-groovy-lint has vscode support and otherwise superior user experience in command line reporting.

However the .groovylintrc.json file isn't compatible with CodeNarc.

Integrating npm-groovy-lint to the build process is not necessarily a huge issue, but it requires creating a custom docker-image (i couldn't see one directly available in dockerhub) and some extra logic. CodeNarc is a bit more straightforward as you can call it from Gradle.

I would like to be able to share the rules of CodeNarc with npm-groovy-lint so that i don't have to maintain them in two different files for both tools.

I can use a groovy rule set file directly with codenarc as configuration, npm-groovy-lint appears to have support for CodeNarc configuration files based on the help text.

-r, --rulesets String
RuleSet file(s) to use for linting. If it is a directory, all rulesets will be used. RuleSet file definition:
http://codenarc.github.io/CodeNarc/codenarc-creating-ruleset.html. If not specified, npm-groovy-script default one will be used. Can also be a list of rule identifiers with parameters

But when I try to pass the same file as a codenarc config file for npm-groovy-lint as a codenarc parameter it just fails.

I had to remove that .txt from the end to get npm-groovy-lint to react to it, but when I run

npm-groovy-lint -r StarterRuleSet-AllRulesByCategory.groovy

GroovyLint: Error running CodeNarc: 
java.lang.AssertionError: No such rule named [ImplicitReturnStatement]. . Expression: ruleClass. Values: ruleClass = null
	at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:436)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:670)
	at org.codenarc.ruleset.TopLevelDelegate.propertyMissing(RuleSetBuilder.groovy:105)
	at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)

then I tried commenting out that ImplicitReturnStatement rule, i get

GroovyLint: Error running CodeNarc: 
java.lang.AssertionError: No such rule named [rules]. . Expression: ruleClass. Values: ruleClass = null
	at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:436)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:670)
	at org.codenarc.ruleset.TopLevelDelegate.methodMissing(RuleSetBuilder.groovy:112)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

Having the npm-groovy-lint (and the VSCode plugin) rule configuration be directly compatible and usable with CodeNarc could also solve the problem so I wouldn't have to make a choice between the two: use one for development / IDE integration and then run codenarc in CI.

@unitysipu
Copy link
Author

i also noticed that codenarc doesn't have very nice in-line ignores for issues in code, which npm-groovy-lint is solving, i'm starting to lean towards using npm-groovy-lint exclusively in the build / dev process, but having a pre-built docker image in dockerhub that has everything needed for running npm-groovy-lint would be really nice so i could just pull that, mount my code and run

@nvuillam
Copy link
Owner

nvuillam commented Jul 2, 2020

I let available the use of CodeNarc rulesets, but only when --codenarcargs are used, else npm-groovy-lint architecture requires a .groovylintrc.json file
I may try to find why we can't directly send RuleSet file, it used to work some time ago ... but if you tell me you switch to .groovylintrc.json for all your cases, i can put this task with low low priority 👼

About docker image... I unfortunately don't have a Linux available on my good old Windows, but if you want to create one, be my guest , I'm waiting frolm your PR :)

It requires only Java 8 / 11 and Node >= 12, so the dockerfile would be something like ->

FROM adoptopenjdk:11-jdk-hotspot-bionic
LABEL maintainer "You ?"

ARG REFRESHED_AT
ENV REFRESHED_AT $REFRESHED_AT

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq && apt-get install -qq --no-install-recommends \
  nodejs \
  yarn \
  && rm -rf /var/lib/apt/lists/*
RUN npm install npm-groovy-lint -g

@unitysipu
Copy link
Author

I think having the option of using codenarc rulesets would be beneficial even if we decide to not use them at the moment. At least if you can figure out why they don't work may reveal something else.

Linux subsystem for windows works great, also VM's (i use them myself). You using windows may explain why --fix adds CRLF line-endings to all my files when it tries to re-indent them. I'll file a new bug for that one.

nvuillam added a commit that referenced this issue Jul 20, 2020
## [5.6.1] 2020-07-20

Fixes:

- [(#62)](#62) using a codenarc ruleset file seems to fail / groovylintrc is not codenarc compatible
@nvuillam nvuillam linked a pull request Jul 20, 2020 that will close this issue
nvuillam added a commit that referenced this issue Jul 20, 2020
## [5.6.1] 2020-07-20

Fixes:

- [(#62)](#62) using a codenarc ruleset file seems to fail / groovylintrc is not codenarc compatible
@nvuillam
Copy link
Owner

In the latest version you have docker image thanks to Dave, a generous contributor, and I also fixed the RuleSet files issue :)

Plz reopen if you see any issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants