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

feat(descriptors, lua): add selene support #3978

Merged
merged 13 commits into from
Sep 10, 2024

Conversation

AlejandroSuero
Copy link
Contributor

Added selene lua linter support to lua descriptors.
#3971

Fixes #

Proposed Changes

  1. Added selene to descriptors

Readiness Checklist

Author/Contributor

  • Add entry to the CHANGELOG listing the change and linking to the corresponding issue (if appropriate)
  • If documentation is needed for this change, has that been included in this pull request

Reviewing Maintainer

  • Label as breaking if this is a large fundamental change
  • Label as either automation, bug, documentation, enhancement, infrastructure, or performance

@echoix
Copy link
Collaborator

echoix commented Sep 9, 2024

@nvuillam and what is needed as test file for a new linter?

@echoix
Copy link
Collaborator

echoix commented Sep 9, 2024

/build

Command run output
Build command workflow started.
Installing dependencies
Running script ./build.sh

Copy link
Contributor

github-actions bot commented Sep 9, 2024

Build command workflow failed.

@echoix
Copy link
Collaborator

echoix commented Sep 9, 2024

Since updating the repo from the new linter modifies some workflow files, I need a human to run the build command.

If you are on Linux, it is ./build.sh, otherwise,

pip install pipx
pipx install hatch
hatch shell

hatch run build:build

@AlejandroSuero
Copy link
Contributor Author

@echoix I ran it from a MacOS and ./build.sh error because import git. After hatch run build:build it said import jsonschema when running ./build.sh.

After hatch run build:build:

Screenshot 2024-09-09 at 14 59 39

Do I commit all these files, right?

@echoix
Copy link
Collaborator

echoix commented Sep 9, 2024

Yep, the same files that you can see in the logs of the workflow I tried to do automatically, but couldn't. (We don't add new linters often nowadays, so it wasn't expected to work everywhere)

@nvuillam
Copy link
Member

nvuillam commented Sep 9, 2024

@nvuillam and what is needed as test file for a new linter?

About tests, let's see if the ones existing for luacheck do the work :)

https://github.com/oxsecurity/megalinter/tree/main/.automation/test/lua

@nvuillam
Copy link
Member

nvuillam commented Sep 9, 2024

@AlejandroSuero , I think you can factorize the installation of lua at descriptor level (install property also defined at top level )

And keep at linter level only what is purely related to the linter :)

Example with powershell: https://github.com/oxsecurity/megalinter/blob/main/megalinter/descriptors/powershell.megalinter-descriptor.yml

@AlejandroSuero
Copy link
Contributor Author

@nvuillam here are the results for selene in existing tests:

Screenshot 2024-09-09 at 19 38 55

@nvuillam
Copy link
Member

nvuillam commented Sep 9, 2024

@AlejandroSuero can you update the test cases so they work with both luacheck and selene ?

Otherwise, it's possible to create a test cases folder just for lua_selene and set property test_folder in selene descriptor, but if we can avoid that I prefer :)

@AlejandroSuero
Copy link
Contributor Author

@AlejandroSuero , I think you can factorize the installation of lua at descriptor level (install property also defined at top level )

And keep at linter level only what is purely related to the linter :)

Example with powershell: https://github.com/oxsecurity/megalinter/blob/main/megalinter/descriptors/powershell.megalinter-descriptor.yml

On the powershell one the top-level install it installs powershell itself, but then the installs on the linters are separated from that.

Do I move the luacheck install and selene install into the same one in the top-level?

@AlejandroSuero
Copy link
Contributor Author

With the commit 442fbf7 the test results are:

Screenshot 2024-09-09 at 19 52 01

Both luacheck and selene fail in lua_bad_1.lua and pass in lua_good_1.lua as expected.

@echoix
Copy link
Collaborator

echoix commented Sep 9, 2024

@AlejandroSuero , I think you can factorize the installation of lua at descriptor level (install property also defined at top level )

And keep at linter level only what is purely related to the linter :)

Example with powershell: https://github.com/oxsecurity/megalinter/blob/main/megalinter/descriptors/powershell.megalinter-descriptor.yml

The next linter (StyLua) is a Docker copy-only linter though, so in the individual linter image, the language-level install will be suboptimal.

- g++
dockerfile:
- |
RUN cargo install --branch main --git https://github.com/Kampfkarren/selene selene
Copy link
Collaborator

Choose a reason for hiding this comment

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

We try to use official releases, so maybe try the following:

Suggested change
RUN cargo install --branch main --git https://github.com/Kampfkarren/selene selene
RUN cargo install selene@0.27.1

Copy link
Collaborator

Choose a reason for hiding this comment

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

Im still trying to find the correct syntax to keep the version number updated

Copy link
Contributor Author

@AlejandroSuero AlejandroSuero Sep 9, 2024

Choose a reason for hiding this comment

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

For what I saw with cargo in the rust descriptor, it's just being omitted (just using the crate name):

Same with npm packages:

install:
npm:
- eslint
- eslint-config-airbnb
- eslint-config-prettier
- eslint-config-standard
- eslint-plugin-import
- eslint-plugin-jest
- eslint-plugin-node
- eslint-plugin-prettier
- eslint-plugin-promise
- eslint-plugin-vue
- "@babel/core"
- "@babel/eslint-parser"
- "@microsoft/eslint-formatter-sarif"

But different in here, using ARG:

install:
dockerfile:
- |-
# renovate: datasource=docker depName=mstruebing/editorconfig-checker
ARG EDITORCONFIG_EDITORCONFIG_CHECKER_VERSION=v3.0.3
- FROM mstruebing/editorconfig-checker:${EDITORCONFIG_EDITORCONFIG_CHECKER_VERSION} AS editorconfig-checker
- COPY --link --from=editorconfig-checker /usr/bin/ec /usr/bin/editorconfig-checker

Copy link
Collaborator

Choose a reason for hiding this comment

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

We weren't pinning packages up until a couple weeks ago, from my push to make keeping them updatable manageable. So you'll find lots of places where they aren't implemented yet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do I leave it with [email protected] or just selene for the time being.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can try with this: #3978 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@echoix LGTM 👍

- g++
dockerfile:
- |
RUN cargo install --branch main --git https://github.com/Kampfkarren/selene selene
Copy link
Collaborator

Choose a reason for hiding this comment

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

@nvuillam where does cargo get set up in individual linters? As it isn't being built in the PR, we don't see it fail yet

- g++
dockerfile:
- |
RUN cargo install --branch main --git https://github.com/Kampfkarren/selene selene
Copy link
Collaborator

Choose a reason for hiding this comment

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

Im still trying to find the correct syntax to keep the version number updated

AlejandroSuero and others added 2 commits September 9, 2024 22:58
Co-authored-by: Edouard Choinière <[email protected]>
Co-authored-by: Edouard Choinière <[email protected]>
@echoix
Copy link
Collaborator

echoix commented Sep 9, 2024

/build

Command run output
Build command workflow started.
Installing dependencies
Running script ./build.sh
Build command workflow completed updating files.

@echoix
Copy link
Collaborator

echoix commented Sep 9, 2024

I'm running tests of individual linters in echoix#120

@echoix echoix enabled auto-merge (squash) September 10, 2024 10:08
@echoix echoix merged commit 64261ae into oxsecurity:main Sep 10, 2024
6 checks passed
@AlejandroSuero AlejandroSuero deleted the add-lua-linter-selene branch September 10, 2024 10:33
@echoix
Copy link
Collaborator

echoix commented Sep 10, 2024

Thanks again! I assure you, the StyLua is way easier to integrate, it's only a copy operation

@nvuillam
Copy link
Member

Great job @AlejandroSuero , i'll mention you in the LinkedIn post at the next MegaLinter release 😊

@AlejandroSuero
Copy link
Contributor Author

@nvuillam @echoix thanks for the feedback and the help.

image

Should this be the way to copy it?

https://github.com/JohnnyMorganz/StyLua?tab=readme-ov-file#docker

https://hub.docker.com/r/johnnymorganz/stylua/tags

@echoix
Copy link
Collaborator

echoix commented Sep 10, 2024

Yes, but I think there's missing the $ for using the var

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 this pull request may close these issues.

Add LUA support
3 participants