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

Only Run npm-package-json-lint When package.json is Present #2280

Merged
merged 6 commits into from
Jan 29, 2023

Conversation

Kurt-von-Laven
Copy link
Collaborator

@Kurt-von-Laven Kurt-von-Laven commented Jan 20, 2023

Fixes #2279.

Proposed Changes

  1. Only run npm-package-json-lint when package.json is present.
  2. Don't include REPOSITORY linters in warning about missing linters.
  3. Make minor syntactic simplifications in directly related code.

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

@Kurt-von-Laven Kurt-von-Laven added the bug Something isn't working label Jan 20, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jan 21, 2023

Codecov Report

Merging #2280 (c481644) into main (cc77d0c) will increase coverage by 0.63%.
The diff coverage is 20.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #2280      +/-   ##
==========================================
+ Coverage   82.39%   83.02%   +0.63%     
==========================================
  Files         171      171              
  Lines        4521     4513       -8     
==========================================
+ Hits         3725     3747      +22     
+ Misses        796      766      -30     
Impacted Files Coverage Δ
megalinter/flavor_factory.py 77.46% <20.00%> (+6.57%) ⬆️
megalinter/reporters/UpdatedSourcesReporter.py 89.74% <0.00%> (+2.56%) ⬆️
...alinter/tests/test_megalinter/helpers/utilstest.py 89.01% <0.00%> (+8.05%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@nvuillam
Copy link
Member

nvuillam commented Jan 21, 2023

🦙 MegaLinter status: ⚠️ WARNING

Descriptor Linter Files Fixed Errors Elapsed time
✅ BASH bash-exec 7 0 0.02s
✅ BASH shellcheck 7 0 0.41s
✅ BASH shfmt 7 0 0 0.04s
✅ COPYPASTE jscpd yes no 2.61s
✅ DOCKERFILE hadolint 105 0 8.19s
✅ JSON eslint-plugin-jsonc 21 0 0 1.85s
✅ JSON jsonlint 19 0 0.21s
✅ JSON npm-package-json-lint yes no 0.62s
✅ JSON v8r 21 0 14.42s
⚠️ MARKDOWN markdownlint 309 2 229 6.09s
✅ MARKDOWN markdown-link-check 309 0 5.22s
✅ MARKDOWN markdown-table-formatter 309 2 0 17.24s
✅ OPENAPI spectral 1 0 0.94s
⚠️ PYTHON bandit 176 45 2.47s
✅ PYTHON black 176 0 0 3.8s
✅ PYTHON flake8 176 0 1.87s
✅ PYTHON isort 176 0 0 0.45s
✅ PYTHON mypy 176 0 7.08s
✅ PYTHON pylint 176 0 12.02s
⚠️ PYTHON pyright 176 280 18.74s
✅ REPOSITORY checkov yes no 27.16s
⚠️ REPOSITORY devskim yes 61 1.23s
✅ REPOSITORY dustilock yes no 1.6s
✅ REPOSITORY git_diff yes no 0.04s
✅ REPOSITORY secretlint yes no 5.09s
✅ REPOSITORY syft yes no 3.25s
✅ REPOSITORY trivy yes no 18.08s
✅ SPELL cspell 730 0 18.91s
✅ SPELL misspell 551 2 0 0.51s
✅ XML xmllint 3 0 0 0.03s
✅ YAML prettier 81 0 0 2.55s
✅ YAML v8r 23 0 55.97s
✅ YAML yamllint 82 0 1.47s

See detailed report in MegaLinter reports

You could have same capabilities but better runtime performances if you request a new MegaLinter flavor.

MegaLinter is graciously provided by OX Security

Copy link
Member

@nvuillam nvuillam left a comment

Choose a reason for hiding this comment

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

Nice one :) to finalize it, plz check comment, + merge main into your branch :)

# Manage cases where linters are missing in flavor
if len(missing_linters) > 0:
# Do not warn/stop if missing linters are repository ones (mostly OX.security related)
if not are_all_repository_linters(missing_linters):
Copy link
Member

Choose a reason for hiding this comment

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

@Kurt-von-Laven plz could you rename are_all_repository_linters into are_ignorable_linters, and move your check inside the method ? thanks :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason I moved the check up here was that I didn't think we should be including the repository linters in missing_linters since we display its contents to the user. I can decompose the check (and rename the helper method) and retain the effect of the commit copied below, but it feels indirect to add the linters into this list only to then immediately remove them. I could alternatively revert the commit copied below (and rename the helper method) if you would rather we continue listing these linters as missing.

Don't warn that REPOSITORY linters are missing

Some REPOSITORY linters are intentionally omitted from flavors to keep their size small and performance fast. Hence, their absence from a flavor isn't considered an error when FAIL_IF_MISSING_LINTER_IN_FLAVOR is true. Therefore, omit them from the list of missing linters displayed to the user to avoid confusion.

Copy link
Member

Choose a reason for hiding this comment

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

nah that's ok ^^

Copy link
Member

@nvuillam nvuillam Jan 31, 2023

Choose a reason for hiding this comment

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

@Kurt-von-Laven I think you broke something here :(
Now the beta version of python flavor crashes before it looks for devskim, which is not in this flavor on purpose :/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can you link me to or paste the stack trace or error message? All of the checks that I see passed when this PR was merged to main, so I'm guessing this is an issue that snuck past CI?

Copy link
Member

Choose a reason for hiding this comment

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

But the latest one works... I'm kind of lost, maybe it was just a version of beta that was wrongly built >_<
https://github.com/oxsecurity/megalinter/actions/runs/4052028152/jobs/6970984591

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, yes, I remember seeing that error inconsistently while working on this pull request and I believe on #2275 as well, so I assumed it was unrelated to either. It sounds like this may be a job for git bisect since we aren't sure when it started, although it probably would have to be scripted to try several times since it's not reproducing consistently.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

It impacts mega-linter-runner tests, which use javascript flavor
https://github.com/oxsecurity/megalinter/actions/workflows/mega-linter-for-runner.yml

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I were to cd mega-linter-runner once and then npm run test repeatedly at each Git bisection point, would that be likely to isolate the issue to a particular commit?

@nvuillam
Copy link
Member

nvuillam commented Jan 24, 2023

@Kurt-von-Laven Another thought... why not just adding the following in the descriptor ?

active_only_if_file_found:
  - "package.json"

Copy link
Collaborator Author

@Kurt-von-Laven Kurt-von-Laven left a comment

Choose a reason for hiding this comment

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

Oh neat! Thanks for teaching me about active_only_if_file_found. Yes, I'll do that instead of exempting npm-package-json-lint from the missing linter list then.

# Manage cases where linters are missing in flavor
if len(missing_linters) > 0:
# Do not warn/stop if missing linters are repository ones (mostly OX.security related)
if not are_all_repository_linters(missing_linters):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason I moved the check up here was that I didn't think we should be including the repository linters in missing_linters since we display its contents to the user. I can decompose the check (and rename the helper method) and retain the effect of the commit copied below, but it feels indirect to add the linters into this list only to then immediately remove them. I could alternatively revert the commit copied below (and rename the helper method) if you would rather we continue listing these linters as missing.

Don't warn that REPOSITORY linters are missing

Some REPOSITORY linters are intentionally omitted from flavors to keep their size small and performance fast. Hence, their absence from a flavor isn't considered an error when FAIL_IF_MISSING_LINTER_IN_FLAVOR is true. Therefore, omit them from the list of missing linters displayed to the user to avoid confusion.

The former is slightly faster as it generally doesn't create a new list.
Some REPOSITORY linters are intentionally omitted from flavors to keep
their size small and performance fast. Hence, their absence from a
flavor isn't considered an error when FAIL_IF_MISSING_LINTER_IN_FLAVOR
is true. Therefore, omit them from the list of missing linters displayed
to the user to avoid confusion.
Reduce indentation by inverting test, and prefer the more Pythonic test
not list to len(list) == 0 for simplicity. Remove some comments rendered
unnecessary via this more direct expression of our intent.
npm-package-json-lint only lints Node.js package.json files, so only run
it when package.json is present. npm-package-json-lint is correctly
omitted from most flavors. Many non-Node.js projects contain other JSON
files, so this change prevents false positives when
FAIL_IF_MISSING_LINTER_IN_FLAVOR is true.
@nvuillam
Copy link
Member

nvuillam commented Jan 26, 2023

🦙 MegaLinter status: ⚠️ WARNING

Descriptor Linter Files Fixed Errors Elapsed time
✅ BASH bash-exec 7 0 0.02s
✅ BASH shellcheck 7 0 0.43s
✅ BASH shfmt 7 0 0 0.38s
✅ COPYPASTE jscpd yes no 3.24s
✅ DOCKERFILE hadolint 105 0 10.97s
✅ JSON eslint-plugin-jsonc 21 0 0 2.67s
✅ JSON jsonlint 19 0 0.31s
✅ JSON v8r 21 0 16.6s
⚠️ MARKDOWN markdownlint 309 0 229 7.57s
✅ MARKDOWN markdown-link-check 309 0 5.97s
✅ MARKDOWN markdown-table-formatter 309 0 0 19.4s
✅ OPENAPI spectral 1 0 0.91s
⚠️ PYTHON bandit 176 45 2.78s
✅ PYTHON black 176 0 0 5.66s
✅ PYTHON flake8 176 0 2.5s
✅ PYTHON isort 176 0 0 0.83s
✅ PYTHON mypy 176 0 9.07s
✅ PYTHON pylint 176 0 15.55s
⚠️ PYTHON pyright 176 282 22.82s
✅ REPOSITORY checkov yes no 32.39s
✅ REPOSITORY git_diff yes no 0.39s
✅ REPOSITORY secretlint yes no 8.29s
✅ REPOSITORY trivy yes no 29.35s
✅ SPELL cspell 730 0 27.3s
✅ SPELL misspell 551 0 0 1.0s
✅ XML xmllint 3 0 0 0.45s
✅ YAML prettier 81 0 0 3.41s
✅ YAML v8r 23 0 62.65s
✅ YAML yamllint 82 0 1.7s

See detailed report in MegaLinter reports

MegaLinter is graciously provided by OX Security

@Kurt-von-Laven Kurt-von-Laven changed the title Don't Treat npm-package-json-lint as Missing From Flavors Only Run npm-package-json-lint When package.json is Present Jan 26, 2023
@Kurt-von-Laven
Copy link
Collaborator Author

The test failures seem unrelated to this PR.

@nvuillam
Copy link
Member

Unauthentified calls to api.github.com limits reached , as usual :/

Let's run the again :)

Copy link
Member

@nvuillam nvuillam left a comment

Choose a reason for hiding this comment

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

Good catch ! :)

# Manage cases where linters are missing in flavor
if len(missing_linters) > 0:
# Do not warn/stop if missing linters are repository ones (mostly OX.security related)
if not are_all_repository_linters(missing_linters):
Copy link
Member

Choose a reason for hiding this comment

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

nah that's ok ^^

@nvuillam nvuillam merged commit 40631ba into main Jan 29, 2023
@nvuillam nvuillam deleted the missing-linter branch January 29, 2023 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

npm-package-json-lint Shouldn't Trigger FAIL_IF_MISSING_LINTER_IN_FLAVOR
3 participants