From c2045ac03cf0922d6a488202c2e7c0abc5d7c9c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?AoMe=20=C2=B7=20=E9=9D=92=E7=9B=AE?= <71392160+AlejandroSuero@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:53:56 +0200 Subject: [PATCH] feat(descriptors, lua): add `stylua` support (#3985) * feat(descriptors, lua): add `stylua` support * feat: add `stylua` and `johnnymorganz` and sorted * fix: make changes to fit `stylua` and lua linters * feat: build after changes * fix: `stylua` to `Stylua` * fix: use correct var syntax * fix: use lowercase repo name * fix: modify dockerfile commands * fix(test): make test error * feat: use `cargo` installation --- .../generated/linter-links-previews.json | 5 + .automation/test/lua/lua_good_1.lua | 8 +- .cspell.json | 6 +- .github/workflows/deploy-BETA-linters.yml | 1 + .github/workflows/deploy-DEV-linters.yml | 1 + .github/workflows/deploy-RELEASE-linters.yml | 1 + Dockerfile | 6 +- docs/standalone-linters.md | 1 + linters/lua_stylua/Dockerfile | 245 ++++++++++++++++++ .../descriptors/lua.megalinter-descriptor.yml | 41 +++ .../megalinter-configuration.jsonschema.json | 1 + .../linters/lua_stylua_test.py | 14 + 12 files changed, 323 insertions(+), 7 deletions(-) create mode 100644 linters/lua_stylua/Dockerfile create mode 100644 megalinter/tests/test_megalinter/linters/lua_stylua_test.py diff --git a/.automation/generated/linter-links-previews.json b/.automation/generated/linter-links-previews.json index 583ada453d7..b31a0b9906b 100644 --- a/.automation/generated/linter-links-previews.json +++ b/.automation/generated/linter-links-previews.json @@ -539,6 +539,11 @@ "image": null, "title": "A mighty, modern style linter \u00b7 stylelint" }, + "stylua": { + "description": "An opinionated Lua code formatter. Contribute to JohnnyMorganz/StyLua development by creating an account on GitHub.", + "image": "https://opengraph.githubassets.com/7b8419175a313d68fb5f334f872c05c1a370b31c1e9e8a96cb799184854e4cc0/JohnnyMorganz/StyLua", + "title": "GitHub - JohnnyMorganz/StyLua: An opinionated Lua code formatter" + }, "swiftlint": { "description": "A tool to enforce Swift style and conventions. Contribute to realm/SwiftLint development by creating an account on GitHub.", "image": "https://avatars3.githubusercontent.com/u/7575099?s=400&v=4", diff --git a/.automation/test/lua/lua_good_1.lua b/.automation/test/lua/lua_good_1.lua index 6e8b66c671d..dde791852de 100644 --- a/.automation/test/lua/lua_good_1.lua +++ b/.automation/test/lua/lua_good_1.lua @@ -1,13 +1,13 @@ local embracer = {} local function helper(opt) - -- NYI wontfix - print(opt) + -- NYI wontfix + print(opt) end function embracer.embrace(opt) - opt = opt or "default" - return helper(opt.."?") + opt = opt or "default" + return helper(opt .. "?") end return embracer diff --git a/.cspell.json b/.cspell.json index 3b064e96160..61f496f96ae 100644 --- a/.cspell.json +++ b/.cspell.json @@ -43,8 +43,8 @@ "REPOSITORYNAME", "RQASWB", "SCSSLINT", - "St\u00e9phane", "SOURCEBRANCHNAME", + "St\u00e9phane", "Ywarn", "abefhkmnptuvx", "admiralawkbar", @@ -94,15 +94,16 @@ "has-tostringtag", "hiqr", "humanwhocodes", + "iisisrael", "ilrsD", "imple", "iname", "inimal", "is-arrayish", "isaacs", + "johnnymorganz", "kleur", "kxdddddddoc", - "iisisrael", "lKXXXX0", "leavevmode", "loadscope", @@ -156,6 +157,7 @@ "sffamily", "shelljs", "sisteransi", + "stylua", "taketalk", "tootallnate", "tous", diff --git a/.github/workflows/deploy-BETA-linters.yml b/.github/workflows/deploy-BETA-linters.yml index 829803560b9..8c9d5fd2936 100644 --- a/.github/workflows/deploy-BETA-linters.yml +++ b/.github/workflows/deploy-BETA-linters.yml @@ -103,6 +103,7 @@ jobs: "latex_chktex", "lua_luacheck", "lua_selene", + "lua_stylua", "markdown_markdownlint", "markdown_markdown_link_check", "markdown_markdown_table_formatter", diff --git a/.github/workflows/deploy-DEV-linters.yml b/.github/workflows/deploy-DEV-linters.yml index 8209d5cb1c3..803f355ce42 100644 --- a/.github/workflows/deploy-DEV-linters.yml +++ b/.github/workflows/deploy-DEV-linters.yml @@ -85,6 +85,7 @@ jobs: "latex_chktex", "lua_luacheck", "lua_selene", + "lua_stylua", "markdown_markdownlint", "markdown_markdown_link_check", "markdown_markdown_table_formatter", diff --git a/.github/workflows/deploy-RELEASE-linters.yml b/.github/workflows/deploy-RELEASE-linters.yml index e3bfef34016..676b0072892 100644 --- a/.github/workflows/deploy-RELEASE-linters.yml +++ b/.github/workflows/deploy-RELEASE-linters.yml @@ -98,6 +98,7 @@ jobs: "latex_chktex", "lua_luacheck", "lua_selene", + "lua_stylua", "markdown_markdownlint", "markdown_markdown_link_check", "markdown_markdown_table_formatter", diff --git a/Dockerfile b/Dockerfile index c89aa81130d..4e981f327ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -119,6 +119,8 @@ ARG DETEKT_VERSION=1.23.7 # renovate: datasource=crate depName=selene ARG LUA_SELENE_VERSION=0.27.1 +# renovate: datasource=crate depName=stylua +ARG LUA_STYLUA_VERSION=0.20.0 # renovate: datasource=nuget depName=PSScriptAnalyzer registryUrl=https://www.powershellgallery.com/api/v2/ ARG PSSA_VERSION='1.22.0' @@ -219,7 +221,7 @@ RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin || true && \ #CARGO__START RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain stable \ && export PATH="/root/.cargo/bin:${PATH}" \ - && rustup component add clippy && cargo install --force --locked sarif-fmt shellcheck-sarif selene@${LUA_SELENE_VERSION} \ + && rustup component add clippy && cargo install --force --locked sarif-fmt shellcheck-sarif selene@${LUA_SELENE_VERSION} stylua@${LUA_STYLUA_VERSION} \ && rm -rf /root/.cargo/registry /root/.cargo/git /root/.cache/sccache ENV PATH="/root/.cargo/bin:${PATH}" #CARGO__END @@ -678,6 +680,8 @@ RUN wget --quiet https://github.com/pmd/pmd/releases/download/pmd_releases%2F${P # # selene installation # +# stylua installation +# # perlcritic installation && curl -fsSL https://raw.githubusercontent.com/skaji/cpm/main/cpm | perl - install -g --show-build-log-on-failure --without-build --without-test --without-runtime Perl::Critic \ && rm -rf /root/.perl-cpm diff --git a/docs/standalone-linters.md b/docs/standalone-linters.md index 6c37f2f37f1..557c50439d6 100644 --- a/docs/standalone-linters.md +++ b/docs/standalone-linters.md @@ -53,6 +53,7 @@ | LATEX_CHKTEX | oxsecurity/megalinter-only-latex_chktex:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-latex_chktex/beta) | | LUA_LUACHECK | oxsecurity/megalinter-only-lua_luacheck:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-lua_luacheck/beta) | | LUA_SELENE | oxsecurity/megalinter-only-lua_selene:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-lua_selene/beta) | +| LUA_STYLUA | oxsecurity/megalinter-only-lua_stylua:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-lua_stylua/beta) | | MAKEFILE_CHECKMAKE | oxsecurity/megalinter-only-makefile_checkmake:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-makefile_checkmake/beta) | | MARKDOWN_MARKDOWNLINT | oxsecurity/megalinter-only-markdown_markdownlint:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-markdown_markdownlint/beta) | | MARKDOWN_REMARK_LINT | oxsecurity/megalinter-only-markdown_remark_lint:beta | ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/oxsecurity/megalinter-only-markdown_remark_lint/beta) | diff --git a/linters/lua_stylua/Dockerfile b/linters/lua_stylua/Dockerfile new file mode 100644 index 00000000000..4d1fac15d1d --- /dev/null +++ b/linters/lua_stylua/Dockerfile @@ -0,0 +1,245 @@ +# syntax=docker/dockerfile:1 +########################################### +########################################### +## Dockerfile to run MegaLinter ## +########################################### +########################################### + +# @not-generated + +############################################################################################# +## @generated by .automation/build.py using descriptor files, please do not update manually ## +############################################################################################# +#ARGTOP__START + +#ARGTOP__END + +############################################################################################# +## @generated by .automation/build.py using descriptor files, please do not update manually ## +############################################################################################# +#FROM__START + +#FROM__END + +################## +# Build wheel for megalinter python package +################## +FROM ghcr.io/astral-sh/uv:0.4.7 AS uv +FROM python:3.12.5-alpine3.20 AS build-ml-core +WORKDIR / +COPY pyproject.toml . +COPY --from=uv /uv /bin/uv +RUN --mount=type=cache,target=/root/.cache/uv \ + uv pip install --system -r pyproject.toml +COPY . . +RUN --mount=type=cache,target=/root/.cache/uv \ + uv pip install --system . + +################## +# Get base image # +################## +FROM python:3.12.5-alpine3.20 + +############################################################################################# +## @generated by .automation/build.py using descriptor files, please do not update manually ## +############################################################################################# +#ARG__START +# renovate: datasource=crate depName=stylua +ARG LUA_STYLUA_VERSION=0.20.0 +#ARG__END + +#################### +# Run APK installs # +#################### + +WORKDIR / + +############################################################################################# +## @generated by .automation/build.py using descriptor files, please do not update manually ## +############################################################################################# +#APK__START +RUN apk add --no-cache \ + bash \ + ca-certificates \ + curl \ + gcc \ + git \ + git-lfs \ + libffi-dev \ + make \ + musl-dev \ + openssh \ + readline-dev \ + && git config --global core.autocrlf true +#APK__END + +# PATH for golang & python +ENV GOROOT=/usr/lib/go \ + GOPATH=/go + # PYTHONPYCACHEPREFIX="$HOME/.cache/cpython/" NV: not working for all packages :/ +# hadolint ignore=DL3044 +ENV PATH="$PATH":"$GOROOT"/bin:"$GOPATH"/bin +RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin || true && \ + # Ignore npm package issues + yarn config set ignore-engines true || true + +############################## +# Installs rust dependencies # +############################################################################################# +## @generated by .automation/build.py using descriptor files, please do not update manually ## +############################################################################################# + +#CARGO__START +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain stable \ + && export PATH="/root/.cargo/bin:${PATH}" \ + && cargo install --force --locked stylua@${LUA_STYLUA_VERSION} \ + && rm -rf /root/.cargo/registry /root/.cargo/git /root/.cache/sccache /root/.rustup +ENV PATH="/root/.cargo/bin:${PATH}" +#CARGO__END + +################################ +# Installs python dependencies # +############################################################################################# +## @generated by .automation/build.py using descriptor files, please do not update manually ## +############################################################################################# + +#PIPVENV__START + +#PIPVENV__END + +############################ +# Install NPM dependencies # +############################################################################################# +## @generated by .automation/build.py using descriptor files, please do not update manually ## +############################################################################################# + +ENV NODE_OPTIONS="--max-old-space-size=8192" \ + NODE_ENV=production +#NPM__START + +#NPM__END + +# Add node packages to path # +ENV PATH="/node-deps/node_modules/.bin:${PATH}" \ + NODE_PATH="/node-deps/node_modules" + +############################## +# Installs ruby dependencies # +############################################################################################# +## @generated by .automation/build.py using descriptor files, please do not update manually ## +############################################################################################# + +#GEM__START + +#GEM__END + +############################## +# COPY instructions # +############################################################################################# +## @generated by .automation/build.py using descriptor files, please do not update manually ## +############################################################################################# + +#COPY__START + +#COPY__END + +############################################################################################# +## @generated by .automation/build.py using descriptor files, please do not update manually ## +############################################################################################# +#OTHER__START +# LUA installation +RUN wget --tries=5 https://www.lua.org/ftp/lua-5.3.5.tar.gz -O - -q | tar -xzf - \ + && cd lua-5.3.5 \ + && make linux \ + && make install \ + && cd .. && rm -r lua-5.3.5/ + +# +# stylua installation +# +#OTHER__END + +################################ +# Installs python dependencies # +################################ +COPY --from=build-ml-core pyproject.toml README.md ./ +COPY --from=build-ml-core megalinter /megalinter/ +RUN --mount=type=cache,target=/root/.cache/uv,from=build-ml-core \ + --mount=from=uv,source=/uv,target=/bin/uv \ + uv pip install --system -e . + +####################################### +# Copy scripts and rules to container # +####################################### +COPY megalinter/descriptors /megalinter-descriptors +COPY TEMPLATES /action/lib/.automation + +# Copy server scripts +COPY server /server + +########################### +# Get the build arguments # +########################### +ARG BUILD_DATE +ARG BUILD_REVISION +ARG BUILD_VERSION + +################################################# +# Set ENV values used for debugging the version # +################################################# +ENV BUILD_DATE=$BUILD_DATE \ + BUILD_REVISION=$BUILD_REVISION \ + BUILD_VERSION=$BUILD_VERSION + +#FLAVOR__START +ENV MEGALINTER_FLAVOR=none +#FLAVOR__END + +######################################### +# Label the instance and set maintainer # +######################################### +LABEL com.github.actions.name="MegaLinter" \ + com.github.actions.description="The ultimate linters aggregator to make sure your projects are clean" \ + com.github.actions.icon="code" \ + com.github.actions.color="red" \ + maintainer="Nicolas Vuillamy " \ + org.opencontainers.image.created=$BUILD_DATE \ + org.opencontainers.image.revision=$BUILD_REVISION \ + org.opencontainers.image.version=$BUILD_VERSION \ + org.opencontainers.image.authors="Nicolas Vuillamy " \ + org.opencontainers.image.url="https://megalinter.io" \ + org.opencontainers.image.source="https://github.com/oxsecurity/megalinter" \ + org.opencontainers.image.documentation="https://megalinter.io" \ + org.opencontainers.image.vendor="Nicolas Vuillamy" \ + org.opencontainers.image.description="Lint your code base with GitHub Actions" + +#EXTRA_DOCKERFILE_LINES__START +ENV ENABLE_LINTERS=LUA_STYLUA \ + FLAVOR_SUGGESTIONS=false \ + SINGLE_LINTER=LUA_STYLUA \ + PRINT_ALPACA=false \ + LOG_FILE=none \ + SARIF_REPORTER=true \ + TEXT_REPORTER=false \ + UPDATED_SOURCES_REPORTER=false \ + GITHUB_STATUS_REPORTER=false \ + GITHUB_COMMENT_REPORTER=false \ + EMAIL_REPORTER=false \ + FILEIO_REPORTER=false \ + CONFIG_REPORTER=false \ + SARIF_TO_HUMAN=false +RUN mkdir /root/docker_ssh && mkdir /usr/bin/megalinter-sh +EXPOSE 22 +COPY entrypoint.sh /entrypoint.sh +COPY sh /usr/bin/megalinter-sh +COPY sh/megalinter_exec /usr/bin/megalinter_exec +COPY sh/motd /etc/motd +RUN find /usr/bin/megalinter-sh/ -type f -iname "*.sh" -exec chmod +x {} \; && \ + chmod +x entrypoint.sh && \ + chmod +x /usr/bin/megalinter_exec && \ + echo "alias megalinter='python -m megalinter.run'" >> ~/.bashrc && source ~/.bashrc && \ + echo "alias megalinter_exec='/usr/bin/megalinter_exec'" >> ~/.bashrc && source ~/.bashrc +RUN export STANDALONE_LINTER_VERSION="$(python -m megalinter.run --input /tmp --linterversion)" && \ + echo $STANDALONE_LINTER_VERSION +ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] +#EXTRA_DOCKERFILE_LINES__END diff --git a/megalinter/descriptors/lua.megalinter-descriptor.yml b/megalinter/descriptors/lua.megalinter-descriptor.yml index 67b49b94dae..9a72a6f5bed 100644 --- a/megalinter/descriptors/lua.megalinter-descriptor.yml +++ b/megalinter/descriptors/lua.megalinter-descriptor.yml @@ -93,3 +93,44 @@ linters: vscode: - name: selene-vscode url: https://marketplace.visualstudio.com/items?itemName=Kampfkarren.selene-vscode + # STYLUA + - linter_name: stylua + linter_url: https://github.com/JohnnyMorganz/StyLua + linter_repo: https://github.com/JohnnyMorganz/StyLua + linter_rules_url: https://roblox.github.io/lua-style-guide/ + linter_rules_configuration_url: https://github.com/JohnnyMorganz/StyLua?tab=readme-ov-file#configuration + linter_rules_inline_disable_url: https://github.com/JohnnyMorganz/StyLua?tab=readme-ov-file#ignoring-parts-of-a-file + linter_megalinter_ref_url: "no" + config_file_name: stylua.toml + cli_config_arg_name: "--config-path" + cli_version_arg_name: "-V" + cli_lint_extra_args: + - "--check" + examples: + - "stylua --check myfile.lua" + - "stylua --config-path chktexrc.toml --check myfile.lua" + install: + cargo: + - stylua@${LUA_STYLUA_VERSION} + dockerfile: + - |- + # renovate: datasource=crate depName=stylua + ARG LUA_STYLUA_VERSION=0.20.0 + ide: + neovim: + - name: + - nvim-lint + - none-ls + - stylua-nvim + - stylua.nvim + url: + - https://github.com/mfussenegger/nvim-lint + - https://github.com/nvimtools/none-ls.nvim + - https://github.com/ckipp01/stylua-nvim + - https://github.com/wesleimp/stylua.nvim + vscode: + - name: Stylua + url: https://marketplace.visualstudio.com/items?itemName=JohnnyMorganz.stylua + sublime: + - name: Sublime-Pretty-Lua + url: https://packagecontrol.io/packages/Pretty%20Lua diff --git a/megalinter/descriptors/schemas/megalinter-configuration.jsonschema.json b/megalinter/descriptors/schemas/megalinter-configuration.jsonschema.json index 557d6b1169d..346f0a05c6c 100644 --- a/megalinter/descriptors/schemas/megalinter-configuration.jsonschema.json +++ b/megalinter/descriptors/schemas/megalinter-configuration.jsonschema.json @@ -188,6 +188,7 @@ "LATEX_CHKTEX", "LUA_LUACHECK", "LUA_SELENE", + "LUA_STYLUA", "MAKEFILE_CHECKMAKE", "MARKDOWN_MARKDOWNLINT", "MARKDOWN_MARKDOWN_LINK_CHECK", diff --git a/megalinter/tests/test_megalinter/linters/lua_stylua_test.py b/megalinter/tests/test_megalinter/linters/lua_stylua_test.py new file mode 100644 index 00000000000..818211c7279 --- /dev/null +++ b/megalinter/tests/test_megalinter/linters/lua_stylua_test.py @@ -0,0 +1,14 @@ +# !/usr/bin/env python3 +""" +Unit tests for LUA linter stylua +This class has been automatically @generated by .automation/build.py, please don't update it manually +""" + +from unittest import TestCase + +from megalinter.tests.test_megalinter.LinterTestRoot import LinterTestRoot + + +class lua_stylua_test(TestCase, LinterTestRoot): + descriptor_id = "LUA" + linter_name = "stylua"