Skip to content

Commit

Permalink
remove DS107, RM106, Rename RM116 (#4712)
Browse files Browse the repository at this point in the history
* remove DS107

* added changelog

* removed RM106

* fix tests

* changed the code of RM116

* fixes
  • Loading branch information
YuvHayun authored Dec 16, 2024
1 parent 1b8666d commit 6a1abfd
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 498 deletions.
6 changes: 6 additions & 0 deletions .changelog/4712.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changes:
- description: Removed support for DS107 and RM106 validations - ensure no 'demist'o word in description and readme files for both new & old validate.
type: breaking
- description: Changed the code of RM116 - Validate that the readme file is not to short to RM117 due to error code duplication.
type: breaking
pr_number: 4712
13 changes: 0 additions & 13 deletions demisto_sdk/commands/common/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,6 @@
"code": "DS106",
"related_field": "",
},
"description_contains_demisto_word": {
"code": "DS107",
"related_field": "detaileddescription",
},
"description_missing_dot_at_the_end": {
"code": "DS108",
"related_field": "description",
Expand Down Expand Up @@ -1091,10 +1087,6 @@
"code": "RM105",
"related_field": "readme",
},
"readme_contains_demisto_word": {
"code": "RM106",
"related_field": "readme",
},
"template_sentence_in_readme": {
"code": "RM107",
"related_field": "readme",
Expand Down Expand Up @@ -2879,11 +2871,6 @@ def invalid_description_name():
"and that the integration_name is the same as the folder containing it."
)

@staticmethod
@error_code_decorator
def description_contains_demisto_word(line_nums, yml_or_file):
return f"Found the word 'Demisto' in the description content {yml_or_file} in lines: {line_nums}."

@staticmethod
@error_code_decorator
def description_missing_dot_at_the_end(details: str):
Expand Down
82 changes: 0 additions & 82 deletions demisto_sdk/commands/common/hook_validations/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def __init__(

def is_valid_file(self):
self.is_duplicate_description()
self.verify_demisto_in_description_content()

# Validations that will run only on Markdown file
if (
Expand Down Expand Up @@ -232,87 +231,6 @@ def is_valid_description_name(self):

return True

@error_codes("DS104,DS107")
def verify_demisto_in_description_content(self):
"""
Checks if there are the word 'Demisto' in the description content.
Return:
True if 'Demisto' does not exist in the description content, and False if it does.
"""
description_path = ""
yml_line_num = 0
yml_or_file = ""

# case 1 the file path is for an integration
if find_type(self.file_path) in [
FileType.INTEGRATION,
FileType.BETA_INTEGRATION,
]:
integration_path = self.file_path
is_unified_integration = self.data_dictionary.get("script", {}).get(
"script", ""
) not in {"-", ""}

if is_unified_integration:
description_content = self.data_dictionary.get(
"detaileddescription", ""
)
yml_or_file = "in the yml file"

# find in which line the description begins in the yml
with open(self.file_path) as f:
for line_n, line in enumerate(f.readlines()):
if "detaileddescription:" in line:
yml_line_num = line_n + 1

# if not found try and look for the description file path
else:
yml_or_file = "in the description file"
description_path = (
f"{os.path.splitext(self.file_path)[0]}_description.md"
)

if not Path(description_path).exists():
error_message, error_code = Errors.no_description_file_warning()
self.handle_error(
error_message,
error_code,
file_path=self.file_path,
warning=True,
)
return True

# running on a description file so the file path is the description path
else:
description_path = self.file_path
integration_path = self.file_path.replace("_description.md", ".yml")
yml_or_file = "in the description file"

if description_path:
with open(description_path) as f:
description_content = f.read()

invalid_lines = []
for line_num, line in enumerate(description_content.split("\n")):
if "demisto " in line.lower() or " demisto" in line.lower():
invalid_lines.append(line_num + yml_line_num + 1)

if invalid_lines:
error_message, error_code = Errors.description_contains_demisto_word(
invalid_lines, yml_or_file
)

if self.handle_error(
error_message,
error_code,
file_path=integration_path,
):
self._is_valid = False
return False

return True

def has_markdown_lint_errors(self, file_content: str):
if mdx_server_is_up():
markdown_response = run_markdownlint(file_content)
Expand Down
28 changes: 0 additions & 28 deletions demisto_sdk/commands/common/hook_validations/readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ def is_valid_file(self) -> bool:
self.verify_no_default_sections_left(),
self.verify_readme_is_not_too_short(),
self.is_context_different_in_yml(),
self.verify_demisto_in_readme_content(),
self.verify_template_not_in_readme(),
self.verify_copyright_section_in_readme_content(),
# self.has_no_markdown_lint_errors(),
Expand Down Expand Up @@ -641,33 +640,6 @@ def check_readme_content_contain_text(

return invalid_lines

@error_codes("RM106")
def verify_demisto_in_readme_content(self):
"""
Checks if there are the word 'Demisto' in the README content.
Return:
True if 'Demisto' does not exist in the README content, and False if it does.
"""

# Checks if the Readme.md is in the main repo.
if str(self.file_path.parent) == self.content_path:
return True

is_valid = True
invalid_lines = self.check_readme_content_contain_text(
text_list=["demisto ", " demisto"], is_lower=True
)

if invalid_lines:
error_message, error_code = Errors.readme_contains_demisto_word(
invalid_lines
)
if self.handle_error(error_message, error_code, file_path=self.file_path):
is_valid = False

return is_valid

@error_codes("RM115")
def has_no_markdown_lint_errors(self):
"""
Expand Down
58 changes: 0 additions & 58 deletions demisto_sdk/commands/common/tests/description_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,61 +166,3 @@ def test_is_invalid_description_integration_name(repo):
description_validator = DescriptionValidator(new_name)

assert not description_validator.is_valid_description_name()


def test_demisto_in_description(repo):
"""
Given
- An integration description with the word 'Demisto'.
When
- Running verify_demisto_in_description_content.
Then
- Ensure that the validation fails.
"""

pack = repo.create_pack("PackName")
integration = pack.create_integration("IntName")
integration.create_default_integration()
integration.description.write(
"This checks if we have the word Demisto in the description."
)

with ChangeCWD(repo.path):
description_validator = DescriptionValidator(integration.yml.path)

assert not description_validator.verify_demisto_in_description_content()

description_validator = DescriptionValidator(integration.description.path)

assert not description_validator.verify_demisto_in_description_content()


def test_demisto_not_in_description(repo):
"""
Given
- An integration description without the word 'Demisto'.
When
- Running verify_demisto_in_description_content.
Then
- Ensure that the validation passes.
"""

pack = repo.create_pack("PackName")
integration = pack.create_integration("IntName")
integration.create_default_integration()
integration.description.write(
"This checks if we have the word XSOAR in the description."
)

with ChangeCWD(repo.path):
description_validator = DescriptionValidator(integration.yml.path)

assert description_validator.verify_demisto_in_description_content()

description_validator = DescriptionValidator(integration.description.path)

assert description_validator.verify_demisto_in_description_content()
80 changes: 0 additions & 80 deletions demisto_sdk/commands/common/tests/readme_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,92 +510,12 @@ def test_invalid_short_file(mocker, caplog):
assert short_readme_error in caplog.text


def test_demisto_in_integration_readme(repo):
"""
Given
- An integration README contains the word 'Demisto'.
When
- Running verify_demisto_in_readme_content.
Then
- Ensure that the validation fails.
"""

pack = repo.create_pack("PackName")
integration = pack.create_integration("IntName")

readme_path = glob.glob(
os.path.join(os.path.dirname(integration.yml.path), "*README.md")
)[0]

with open(readme_path, "w") as f:
f.write("This checks if we have the word Demisto in the README.")

with ChangeCWD(repo.path):
readme_validator = ReadMeValidator(integration.readme.path)

assert not readme_validator.verify_demisto_in_readme_content()


def init_readmeValidator(readme_validator, repo, readme_path):
readme_validator.content_path = str(repo.path)
readme_validator.file_path = readme_path
readme_validator.specific_validations = None


def test_demisto_in_repo_readme(mocker, repo):
"""
Given
- A repo README contains the word 'Demisto'.
When
- Running verify_demisto_in_readme_content.
Then
- Ensure that the validation not fails.
"""
from pathlib import Path

readme_path = Path(repo.path) / "README.md"
mocker.patch.object(ReadMeValidator, "__init__", return_value=None)

with open(readme_path, "w") as f:
f.write("This checks if we have the word Demisto in the README.")

with ChangeCWD(repo.path):
readme_validator = ReadMeValidator()
init_readmeValidator(readme_validator, repo, readme_path)
assert readme_validator.verify_demisto_in_readme_content()


def test_demisto_not_in_readme(repo):
"""
Given
- An integration README without the word 'Demisto'.
When
- Running verify_demisto_in_readme_content.
Then
- Ensure that the validation passes.
"""

pack = repo.create_pack("PackName")
integration = pack.create_integration("IntName")

readme_path = glob.glob(
os.path.join(os.path.dirname(integration.yml.path), "*README.md")
)[0]

with open(readme_path, "w") as f:
f.write("This checks if we have the word XSOAR in the README.")

readme_validator = ReadMeValidator(integration.readme.path)

assert readme_validator.verify_demisto_in_readme_content()


def test_verify_template_not_in_readme(repo):
"""
Given
Expand Down
6 changes: 3 additions & 3 deletions demisto_sdk/commands/validate/sdk_validation_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ignorable_errors = [
"BA125",
"BA127",
"GF102",
"DS107",
"DS108",
"IF100",
"IF106",
Expand Down Expand Up @@ -80,7 +79,8 @@ ignorable_errors = [
"LO107",
"DB100",
"GR103",
"GR107"
"GR107",
"RM117"
]

[Custom_Categories]
Expand Down Expand Up @@ -420,7 +420,6 @@ select = [
"DS104",
"DS105",
"DS106",
"DS107",
"DS108",
"SC100",
"SC105",
Expand All @@ -439,6 +438,7 @@ select = [
"RM114",
"RM115",
"RM116",
"RM117",
"CL100",
"PR101",
"CR102",
Expand Down
Loading

0 comments on commit 6a1abfd

Please sign in to comment.