-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add --serverless-rules to sam validate --lint #7950
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
Open
shashax42
wants to merge
6
commits into
aws:develop
Choose a base branch
from
shashax42:feature/serverless-rules-lint
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b524fb7
feat: add --serverless-rules to sam validate --lint
shashax42 ee659b9
Merge branch 'develop' into feature/serverless-rules-lint
vicheey ae6b24c
Merge branch 'develop' into feature/serverless-rules-lint
shashax42 dbdff60
feat: Add --extra-lint-rules option for flexible linting rules support
shashax42 cd68913
docs: Convert Korean comments to English for better readability
shashax42 f75e51d
refactor: improve extra-lint-rules feature based on review feedback
shashax42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# SAM CLI Extra Lint Rules Usage Guide | ||
|
||
The AWS SAM CLI's `validate` command uses [cfn-lint](https://github.com/aws-cloudformation/cfn-lint) for template validation. | ||
SAM CLI now supports additional lint rules through the `--extra-lint-rules` option. | ||
|
||
## Usage | ||
|
||
```bash | ||
sam validate --lint --extra-lint-rules="cfn_lint_serverless.rules" | ||
``` | ||
|
||
## Considerations when Installing SAM CLI with the Installer | ||
|
||
When SAM CLI is installed using the installer, it uses its own Python environment. In this case, additional rule modules must be installed in that environment. There are two approaches: | ||
|
||
1. **Install packages in the installer's Python environment**: Install the required packages in the installer's Python environment. | ||
2. **Specify the full path to the module**: Specify the full path to the package installed in the user's environment. | ||
|
||
## Usage Examples | ||
|
||
### Using Serverless Rules (cfn-lint-serverless) | ||
|
||
```bash | ||
# First, install the package | ||
pip install cfn-lint-serverless | ||
|
||
# Run SAM template validation | ||
sam validate --lint --extra-lint-rules="cfn_lint_serverless.rules" | ||
``` | ||
|
||
### Using Multiple Rule Modules | ||
|
||
#### Method 1: Specify Multiple Modules Separated by Commas | ||
|
||
You can specify multiple rule modules separated by commas in a single option: | ||
|
||
```bash | ||
sam validate --lint --extra-lint-rules="module1.rules,module2.rules,module3.rules" | ||
``` | ||
|
||
Each module is automatically separated and passed to cfn-lint. | ||
|
||
#### Method 2: Use the Option Multiple Times | ||
|
||
You can also specify multiple rule modules by using the `--extra-lint-rules` option multiple times: | ||
|
||
```bash | ||
sam validate --lint --extra-lint-rules="module1.rules" --extra-lint-rules="module2.rules" | ||
``` | ||
|
||
## Notes | ||
|
||
* The previously used `--serverless-rules` option is deprecated. | ||
* It is recommended to use the new `--extra-lint-rules` option. | ||
* If you installed SAM CLI using the installer and additional rules are not working, check if the package is installed in the installer's Python environment. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to pass
multiple=True
to allow the parameter to be passed multiple times (https://click.palletsprojects.com/en/stable/options/#multiple-options and it will be stored as a list).You mentioned in the documentation that that is actually supported, did you test passing it multiple times? (I imagine the last one will just replace any other one if we don't add the
multiple=True
)