Skip to content

Commit

Permalink
change lint_languages to a list instead of set
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-orlando committed Nov 10, 2023
1 parent a70531a commit 6c10200
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions secureli/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,25 +208,25 @@ def _install_secureli(self, folder_path: Path, always_yes: bool) -> VerifyResult

def _prompt_get_lint_config_languages(
self, languages: list[str], always_yes: bool
) -> set[str]:
) -> list[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)
return [*languages]

lint_languages: set[str] = set()
lint_languages: list[str] = []

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)
lint_languages.append(language)

return lint_languages

Expand Down
8 changes: 4 additions & 4 deletions secureli/services/language_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def secret_detection_hook_id(self, languages: list[str]) -> Optional[str]:
:return: The hook ID to use for secrets analysis if supported, otherwise None.
"""
# lint_languages param can be an empty set since we only need secrets detection hooks
language_config = self._build_pre_commit_config(languages, set())
language_config = self._build_pre_commit_config(languages, [])
config = language_config.config_data
secrets_detecting_repos_data = self.data_loader(
"pre-commit/secrets_detecting_repos.yaml"
Expand Down Expand Up @@ -193,20 +193,20 @@ def create_repo(raw_repo: dict) -> Repo:
return HookConfiguration(repos=repos)

def _build_pre_commit_config(
self, languages: list[str], lint_languages: set[str]
self, languages: list[str], lint_languages: list[str]
) -> BuildConfigResult:
"""
Builds the final .pre-commit-config.yaml from all supported repo languages. Also returns any and all
linter configuration data.
:param languages: list of languages to get calculated configuration for.
:param lint_languages: set of languages to add lint pre-commit hooks for.
:param lint_languages: list of languages to add lint pre-commit hooks for.
:return: BuildConfigResult
"""
config_data = []
successful_languages: list[str] = []
linter_configs: list[LinterConfig] = []
config_languages = [*languages, "base"]
config_lint_languages = set([*lint_languages, "base"])
config_lint_languages = [*lint_languages, "base"]

for language in config_languages:
include_linter = language in config_lint_languages
Expand Down
8 changes: 4 additions & 4 deletions tests/actions/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def test_that_prompt_get_lint_config_languages_returns_all_languages_when_always
result = action._prompt_get_lint_config_languages(mock_languages, True)

mock_echo.confirm.assert_not_called()
assert result == set(mock_languages)
assert result == mock_languages


def test_that_prompt_get_lint_config_languages_returns_no_languages(
Expand All @@ -322,7 +322,7 @@ def test_that_prompt_get_lint_config_languages_returns_no_languages(

mock_echo.confirm.assert_called()
assert mock_echo.confirm.call_count == len(mock_languages)
assert result == set()
assert result == []


def test_that_prompt_get_lint_config_languages_returns_all_languages(
Expand All @@ -336,7 +336,7 @@ def test_that_prompt_get_lint_config_languages_returns_all_languages(

mock_echo.confirm.assert_called()
assert mock_echo.confirm.call_count == len(mock_languages)
assert result == set(mock_languages)
assert result == mock_languages


def test_that_prompt_get_lint_config_languages_returns_filtered_languages_based_on_choice(
Expand All @@ -357,4 +357,4 @@ def confirm_side_effect(*args, **kwargs):

mock_echo.confirm.assert_called()
assert mock_echo.confirm.call_count == len(mock_languages)
assert result == set([mock_languages[0]])
assert result == [mock_languages[0]]
8 changes: 4 additions & 4 deletions tests/services/test_language_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def mock_loader_side_effect(resource):
mock_data_loader.side_effect = mock_loader_side_effect

languages = ["RadLang"]
lint_languages = set(languages)
lint_languages = [*languages]

build_config_result = language_support_service._build_pre_commit_config(
languages, lint_languages
Expand Down Expand Up @@ -278,7 +278,7 @@ def test_that_language_support_throws_exception_when_language_config_file_cannot
)

languages = ["RadLang"]
lint_languages = set(languages)
lint_languages = [*languages]

build_config_result = language_support_service._build_pre_commit_config(
languages, lint_languages
Expand Down Expand Up @@ -307,7 +307,7 @@ def test_that_language_support_handles_invalid_language_config(
)

languages = ["RadLang"]
lint_languages = set(languages)
lint_languages = [*languages]

build_config_result = language_support_service._build_pre_commit_config(
languages, lint_languages
Expand Down Expand Up @@ -337,7 +337,7 @@ def test_that_language_support_handles_empty_repos_list(
mock_data_loader.return_value = ""

languages = ["RadLang"]
lint_languages = set(languages)
lint_languages = [*languages]

build_config_result = language_support_service._build_pre_commit_config(
languages, lint_languages
Expand Down

0 comments on commit 6c10200

Please sign in to comment.