Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/common/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ method-naming-style=snake_case
inlinevar-naming-style=snake_case

# Include a hint for the correct naming format with invalid-name.
include-naming-hint=yes
include-naming-hint=no

# Bad variable names which should always be refused, separated by a comma.
bad-names=x,
Expand Down
23 changes: 14 additions & 9 deletions lib/common/pylint_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,26 @@ def generate_pylint_comments(in_path, pylint_spec='/opt/analyzer/lib/common/.pyl
continue

if line[2] in {"C0114 missing-module-docstring",
"C0115 missing-class-docstring",
"C0116 missing-function-docstring",
"C0304 missing-final-newline"}:

status_type = status_mapping['informational']
else:
status_type = status_mapping[line[0]]

pylint_comments.append(Comment(type=status_type,
params={'lineno': line[1],
'code': line[2],
'message': ', '.join(line[3:]),
'bad_code': f'Instead of: \n```python\n{bad}```\n\n' if bad else None,
'good_code': f'Try: \n```python\n{good}```\n\n' if good else None,
'related_info': related,
'details': details},
comment=f'python.pylint.{line[0]}'))
new_comment = Comment(type=status_type,
params={'lineno': line[1],
'code': line[2],
'message': ', '.join(line[3:]),
'bad_code': f'Instead of: \n```python\n{bad}```\n\n' if bad else None,
'good_code': f'Try: \n```python\n{good}```\n\n' if good else None,
'related_info': related,
'details': details},
comment=f'python.pylint.{line[0]}')


if new_comment not in pylint_comments:
pylint_comments.append(new_comment)

return pylint_comments
20 changes: 5 additions & 15 deletions lib/common/pylint_data/messages/invalid-name/details.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
By default, Pylint will enforce
By default, Pylint enforces
[PEP8](https://peps.python.org/pep-0008)-suggested names.

The following naming suggestions are used for Exercism exercises:

- modules (code files): snake_case
- constants: UPPER_CASE
- variables: snake_case (minimum of 3 letters)
- functions: snake_case
- arguments: snake_case
- attributes: snake_case
- classes: PascalCase
- class attributes: any (no specific format)
- class constants: UPPER_CASE
- class methods: snake_case
- inline variables and loop variables: snake_case
For more details on the pitfalls of `_` specifically,
see this Stack Overflow [answer](https://stackoverflow.com/a/5893946)
and [Underscores in Python](https://shahriar.svbtle.com/underscores-in-python)
by Shahriar Tajbakhsh.
15 changes: 1 addition & 14 deletions test/dnd-character/analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"related_info": null,
"details": null
},
"type": "actionable"
"type": "informative"
},
{
"comment": "python.pylint.refactor",
Expand All @@ -40,19 +40,6 @@
},
"type": "actionable"
},
{
"comment": "python.pylint.refactor",
"params": {
"lineno": "19",
"code": "R6301 no-self-use",
"message": "Method could be a function",
"bad_code": "Instead of: \n```python\nclass Person:\n def greeting(self): # [no-self-use]\n print(\"Greetings pythonista!\")\n```\n\n",
"good_code": "Try: \n```python\n# Function\ndef greeting():\n print(\"Greetings pythonista!\")\n\n\n# Static Method\nclass Person:\n @staticmethod\n def greeting():\n print(\"Greetings pythonista!\")\n\n# Use Self\nclass Person:\n name: str = \"Amelia\"\n\n def greeting(self):\n print(f\"Greetings {self.name} the pythonista!\")\n```\n\n",
"related_info": null,
"details": "If a function is not using any class attribute it can be a\n`@staticmethod`, or a function outside the class.\n"
},
"type": "actionable"
},
{
"comment": "python.pylint.refactor",
"params": {
Expand Down
2 changes: 1 addition & 1 deletion test/electric-bill/analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"bad_code": "Instead of: \n```python\nclass cat: # [invalid-name]\n def Meow(self, NUMBER_OF_MEOW): # [invalid-name, invalid-name]\n print(\"Meow\" * NUMBER_OF_MEOW)\n return NUMBER_OF_MEOW\n\n\nCat = cat().Meow(42) # [invalid-name]\n```\n\n",
"good_code": "Try: \n```python\nclass Cat:\n def meow(self, number_of_meow):\n print(\"Meow\" * number_of_meow)\n return number_of_meow\n\n\nCAT = Cat().meow(42)\n```\n\n",
"related_info": null,
"details": "By default, Pylint will enforce\n[PEP8](https://peps.python.org/pep-0008)-suggested names.\n\nThe following naming suggestions are used for Exercism exercises:\n\n- modules (code files): snake_case\n- constants: UPPER_CASE\n- variables: snake_case (minimum of 3 letters)\n- functions: snake_case\n- arguments: snake_case\n- attributes: snake_case\n- classes: PascalCase\n- class attributes: any (no specific format)\n- class constants: UPPER_CASE\n- class methods: snake_case\n- inline variables and loop variables: snake_case\n"
"details": "By default, Pylint enforces\n[PEP8](https://peps.python.org/pep-0008)-suggested names.\nFor more details on the pitfalls of `_` specifically,\n see this Stack Overflow [answer](https://stackoverflow.com/a/5893946)\n and [Underscores in Python](https://shahriar.svbtle.com/underscores-in-python)\n by Shahriar Tajbakhsh.\n"
},
"type": "actionable"
}
Expand Down
2 changes: 1 addition & 1 deletion test/guidos-gorgeous-lasagna/analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"bad_code": "Instead of: \n```python\nclass cat: # [invalid-name]\n def Meow(self, NUMBER_OF_MEOW): # [invalid-name, invalid-name]\n print(\"Meow\" * NUMBER_OF_MEOW)\n return NUMBER_OF_MEOW\n\n\nCat = cat().Meow(42) # [invalid-name]\n```\n\n",
"good_code": "Try: \n```python\nclass Cat:\n def meow(self, number_of_meow):\n print(\"Meow\" * number_of_meow)\n return number_of_meow\n\n\nCAT = Cat().meow(42)\n```\n\n",
"related_info": null,
"details": "By default, Pylint will enforce\n[PEP8](https://peps.python.org/pep-0008)-suggested names.\n\nThe following naming suggestions are used for Exercism exercises:\n\n- modules (code files): snake_case\n- constants: UPPER_CASE\n- variables: snake_case (minimum of 3 letters)\n- functions: snake_case\n- arguments: snake_case\n- attributes: snake_case\n- classes: PascalCase\n- class attributes: any (no specific format)\n- class constants: UPPER_CASE\n- class methods: snake_case\n- inline variables and loop variables: snake_case\n"
"details": "By default, Pylint enforces\n[PEP8](https://peps.python.org/pep-0008)-suggested names.\nFor more details on the pitfalls of `_` specifically,\n see this Stack Overflow [answer](https://stackoverflow.com/a/5893946)\n and [Underscores in Python](https://shahriar.svbtle.com/underscores-in-python)\n by Shahriar Tajbakhsh.\n"
},
"type": "actionable"
}
Expand Down