Skip to content

Commit c19f7eb

Browse files
authored
Merge pull request #2 from pylint-dev/1-add-project-config-setup
1 add project config setup
2 parents ece9823 + 065e01a commit c19f7eb

22 files changed

+355
-3
lines changed

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,12 @@ cython_debug/
157157
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160-
#.idea/
160+
.idea/
161+
162+
# Mr Developer
163+
.mr.developer.cfg
164+
.project
165+
.pydevproject
166+
.idea
167+
env.txt
168+
poetry.lock

.pre-commit-config.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
ci:
2+
skip: [pylint]
3+
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.5.0
7+
hooks:
8+
- id: trailing-whitespace
9+
- id: end-of-file-fixer
10+
- id: mixed-line-ending
11+
args: [--fix=lf]
12+
- id: debug-statements
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: "v0.1.4"
15+
hooks:
16+
- id: ruff
17+
args: ["--fix"]
18+
exclude: "tests/input/"
19+
- repo: https://github.com/psf/black
20+
rev: 23.10.1
21+
hooks:
22+
- id: black
23+
args: [--safe, --line-length=120]
24+
- repo: https://github.com/pre-commit/mirrors-prettier
25+
rev: v3.0.3
26+
hooks:
27+
- id: prettier
28+
args: [--prose-wrap=always, --print-width=88]
29+
- repo: local
30+
hooks:
31+
- id: pylint
32+
name: pylint
33+
entry: py -m poetry run pylint
34+
language: system
35+
types: [python]
36+
args: ["-rn", "-sn", "--fail-on=I"]
37+
exclude: "tests/input/"

CONTRIBUTORS.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Maintainers
2+
-----------
3+
- Peter Hamfelt <[email protected]>
4+
5+
Contributors
6+
------------

README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pylint-ml
2+
=============
3+
4+
About
5+
-----
6+
``pylint-ml`` is a pylint plugin for enhancing code analysis for machine learning and data science

pylint_ml/__init__.py

Whitespace-only changes.

pylint_ml/checkers/__init__.py

Whitespace-only changes.

pylint_ml/checkers/numpy/__init__.py

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Licensed under the MIT: https://mit-license.org/
2+
# For details: https://github.com/pylint-dev/pylint-ml/LICENSE
3+
# Copyright (c) https://github.com/pylint-dev/pylint-ml/CONTRIBUTORS.txt
4+
5+
"""Check for import of numpy library."""
6+
7+
from __future__ import annotations
8+
9+
from astroid import nodes
10+
from pylint.checkers import BaseChecker
11+
from pylint.checkers.utils import only_required_for_messages
12+
from pylint.interfaces import HIGH
13+
14+
15+
class NumpyImportChecker(BaseChecker):
16+
name = "numpy-import"
17+
msgs = {
18+
"W8001": (
19+
"Numpy imported with incorrect alias",
20+
"numpy-import",
21+
"Numpy should be imported with the alias `np` to maintain consistency with common practices. "
22+
"Importing numpy with any other alias can lead to confusion. "
23+
"Consider using `import numpy as np` for clarity and adherence to the convention.",
24+
),
25+
"W8002": (
26+
"Direct import from Numpy discouraged",
27+
"numpy-importfrom",
28+
"Direct imports from Numpy using `from numpy import ...` are discouraged to maintain code clarity and "
29+
"prevent potential conflicts. Numpy should be imported with the alias `np` following common practices. "
30+
"Using any other alias or direct import method can lead to confusion. "
31+
"Consider using `import numpy as np` to adhere to the convention and ensure consistency.",
32+
),
33+
}
34+
35+
@only_required_for_messages("numpy-import")
36+
def visit_import(self, node: nodes.Import) -> None:
37+
for name, alias in node.names:
38+
if name == "numpy" and alias != "np":
39+
self.add_message("numpy-import", node=node, confidence=HIGH)
40+
41+
@only_required_for_messages("numpy-importfrom")
42+
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
43+
if node.modname == "numpy":
44+
self.add_message("numpy-importfrom", node=node, confidence=HIGH)

pylint_ml/checkers/pandas/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)