Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

feat: shared constraints #103

Merged
merged 1 commit into from
Oct 13, 2021
Merged

Conversation

lmt-swallow
Copy link
Member

Description

This PR adds a concept of shared constraints.

A shared constraint is a kind of constraint that is shared among multiple patterns. For instance, in the following rule, a constraint with target: NAME behaves as if they are placed inside each pattern in patterns:

version: "1"
rules:
  - id: "use-trusted-base-images"
    language: dockerfile
    message: |
      Use trusted base images if possible.
    patterns:
      - pattern: FROM :[NAME]
      - pattern: FROM :[NAME] AS :[ALIAS]
      - pattern: FROM :[NAME]@:[HASH]
      - pattern: FROM :[NAME]@:[HASH] AS :[ALIAS]
      - pattern: FROM :[NAME]::[TAG]
      - pattern: FROM :[NAME]::[TAG] AS :[ALIAS]
      - pattern: FROM :[NAME]::[TAG]@:[HASH]
      - pattern: FROM :[NAME]::[TAG]@:[HASH] AS :[ALIAS]
    constraints:
      - target: NAME
        should: be-any-of
        strings:
          - test
          - foo

Checklist

  • I opened a draft PR or added the [WIP] to the title if my PR is not ready for review.
  • I have reviewed the code by myself.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • I have added tests enough to show how your code behaves and that your code works as expected.

Additional Notes

N/A

Signed-off-by: Takashi Yoneuchi <takashi.yoneuchi@shift-js.info>
@lmt-swallow lmt-swallow self-assigned this Oct 13, 2021
@netlify
Copy link

netlify bot commented Oct 13, 2021

✔️ Deploy Preview for cranky-fermi-e6c846 canceled.

🔨 Explore the source changes: 4f4daf0

🔍 Inspect the deploy log: https://app.netlify.com/sites/cranky-fermi-e6c846/deploys/616687406051c600085060f7

@lmt-swallow lmt-swallow added the type: feature New feature label Oct 13, 2021
@codecov-commenter
Copy link

Codecov Report

Merging #103 (4f4daf0) into main (8327b2a) will increase coverage by 0.31%.
The diff coverage is 79.16%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #103      +/-   ##
==========================================
+ Coverage   74.54%   74.85%   +0.31%     
==========================================
  Files          30       30              
  Lines        1693     1710      +17     
==========================================
+ Hits         1262     1280      +18     
+ Misses        431      430       -1     
Impacted Files Coverage Δ
src/core/target.rs 69.81% <71.42%> (+1.85%) ⬆️
src/core/ruleset.rs 68.13% <76.92%> (+2.69%) ⬆️
src/cli/tests/ruleset/generic/mod.rs 100.00% <100.00%> (ø)
src/cli/subcommand/check.rs 61.76% <0.00%> (+1.47%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8327b2a...4f4daf0. Read the comment docs.

@lmt-swallow lmt-swallow merged commit faff7c0 into main Oct 13, 2021
@lmt-swallow lmt-swallow deleted the feature/allow-global-constraints branch October 13, 2021 07:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants