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: 154 Prompt User to Install Code Linters for each Detected Language #332

Merged
merged 10 commits into from
Nov 14, 2023
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ source = secureli

[report]
fail_under = 90
show_missing = true
omit =
tests/*
*/__init__.py
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,4 @@ A special thanks to everyone that has contributed to seCureLI so far:
- Jeff Schumacher
- Caleb Tonn
- Josh Werner
- Kevin Orlando
39 changes: 38 additions & 1 deletion secureli/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,19 @@ def _install_secureli(self, folder_path: Path, always_yes: bool) -> VerifyResult
languages = list(analyze_result.language_proportions.keys())
self.action_deps.echo.print(f"Overall Detected Languages: {languages}")

metadata = self.action_deps.language_support.apply_support(languages)
lint_languages = self._prompt_get_lint_config_languages(
languages, always_yes
)

language_config_result = (
self.action_deps.language_support._build_pre_commit_config(
languages, lint_languages
)
)

metadata = self.action_deps.language_support.apply_support(
languages, language_config_result
)

except (ValueError, LanguageNotSupportedError, InstallFailedError) as e:
self.action_deps.echo.error(
Expand All @@ -160,6 +172,7 @@ def _install_secureli(self, folder_path: Path, always_yes: bool) -> VerifyResult

config = SecureliConfig(
languages=languages,
lint_languages=lint_languages,
version_installed=metadata.version,
)
self.action_deps.secureli_config.save(config)
Expand Down Expand Up @@ -193,6 +206,30 @@ def _install_secureli(self, folder_path: Path, always_yes: bool) -> VerifyResult
analyze_result=analyze_result,
)

def _prompt_get_lint_config_languages(
self, languages: list[str], always_yes: bool
) -> set[str]:
"""
Prompts user to add lint pre-commit hooks for each detected language
:param languages: list of detected languages
:param always_yes: Assume "Yes" to all prompts
:return: set of filtered languages to add lint pre-commit hooks for
"""
if always_yes:
return set(languages)

lint_languages: set[str] = set()

for language in languages:
add_linter = self.action_deps.echo.confirm(
f"Add lint pre-commit hook(s) for {language}?", default_response=True
)

if add_linter:
lint_languages.add(language)

return lint_languages

def _update_secureli(self, always_yes: bool):
"""
Prompts the user to update to the latest secureli install.
Expand Down
2 changes: 2 additions & 0 deletions secureli/repositories/secureli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class SecureliConfig(BaseModel):
languages: Optional[list[str]]
lint_languages: Optional[list[str]]
version_installed: Optional[str]


Expand Down Expand Up @@ -96,6 +97,7 @@ def update(self) -> SecureliConfig:

return SecureliConfig(
languages=[old_config.overall_language],
lint_languages=[old_config.overall_language],
version_installed=old_config.version_installed,
)

Expand Down
27 changes: 0 additions & 27 deletions secureli/resources/files/base-pre-commit.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions secureli/resources/files/csharp-pre-commit.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions secureli/resources/files/java-pre-commit.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions secureli/resources/files/javascript-pre-commit.yaml

This file was deleted.

27 changes: 27 additions & 0 deletions secureli/resources/files/pre-commit/base/base-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-toml
- id: check-json
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: detect-private-key
- id: name-tests-test
args: [--pytest-test-first]
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repos:
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repos:
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repos:
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repos:
10 changes: 10 additions & 0 deletions secureli/resources/files/pre-commit/base/python-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: python-use-type-annotations
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
- id: bandit
args: ["--exclude", "tests/", "--severity-level", "medium"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
exclude: .xcscheme$
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repos:
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repos:
14 changes: 14 additions & 0 deletions secureli/resources/files/pre-commit/lint/csharp-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: local
hooks:
# Note: The dotnet format pre-commit setup combines poorly to be tightly coupled with
# a pre-release version of .net that is old and no one has installed. dotnet format has
# since become a part of .net! So we can use dotnet format already installed on your
# simply. This runs the risk that different folks will run different versions, but
# this is better than nothing.
# see https://github.com/dotnet/format/issues/1350 and the resolution PR at the bottom.
- id: dotnet-format
name: dotnet-format
language: system
entry: dotnet format --include
types: ["c#"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
repos:
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.53.3
hooks:
Expand Down
5 changes: 5 additions & 0 deletions secureli/resources/files/pre-commit/lint/java-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/slalombuild/pre-commit-mirror-checkstyle
rev: v0.1.1
hooks:
- id: checkstyle-java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repos:
- repo: https://github.com/pre-commit/mirrors-eslint
rev: "v8.42.0"
hooks:
- id: eslint
files: \.[j]sx?$ # *.js and *.jsx
types: [file]
args: ["--config", ".secureli/javascript.eslintrc.yaml", "--fix"]
additional_dependencies:
- [email protected]
- [email protected]
- [email protected]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
hooks:
- id: prettier
args:
- --single-quote
- --trailing-comma
- all
types_or: [css, javascript]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/realm/SwiftLint
rev: 0.52.2
hooks:
- id: swiftlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.77.0
hooks:
- id: terraform_tflint
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: https://github.com/pre-commit/mirrors-eslint
rev: "v8.42.0"
hooks:
- id: eslint
files: \.[t]sx?$ # *.ts and *.tsx
types: [file]
args: ["--config", ".secureli/typescript.eslintrc.yaml", "--fix"]
additional_dependencies:
- [email protected]
- [email protected]
- "@typescript-eslint/[email protected]"
- "@typescript-eslint/[email protected]"
- [email protected]
- [email protected]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
hooks:
- id: prettier
args:
- --single-quote
- --trailing-comma
- all
14 changes: 0 additions & 14 deletions secureli/resources/files/python-pre-commit.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions secureli/resources/files/swift-pre-commit.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions secureli/resources/files/terraform-pre-commit.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions secureli/resources/files/typescript-pre-commit.yaml

This file was deleted.

Loading