mirror of
https://github.com/apache/superset.git
synced 2026-04-17 23:25:05 +00:00
chore: move some rules from ruff -> pylint (#34292)
This commit is contained in:
committed by
GitHub
parent
efa8cb6fa4
commit
3f8472ca7b
@@ -105,7 +105,8 @@ repos:
|
||||
- |
|
||||
TARGET_BRANCH=${GITHUB_BASE_REF:-master}
|
||||
git fetch origin "$TARGET_BRANCH"
|
||||
files=$(git diff --name-only --diff-filter=ACM origin/"$TARGET_BRANCH"..HEAD | grep '^superset/.*\.py$' || true)
|
||||
BASE=$(git merge-base origin/"$TARGET_BRANCH" HEAD)
|
||||
files=$(git diff --name-only --diff-filter=ACM "$BASE"..HEAD | grep '^superset/.*\.py$' || true)
|
||||
if [ -n "$files" ]; then
|
||||
pylint --rcfile=.pylintrc --load-plugins=superset.extensions.pylint $files
|
||||
else
|
||||
|
||||
@@ -311,15 +311,16 @@ select = [
|
||||
"Q",
|
||||
"S",
|
||||
"T",
|
||||
"TID",
|
||||
"W",
|
||||
]
|
||||
|
||||
ignore = [
|
||||
"S101",
|
||||
"PT006",
|
||||
"T201",
|
||||
"N999",
|
||||
]
|
||||
|
||||
extend-select = ["I"]
|
||||
|
||||
# Allow fix for all enabled rules (when `--fix`) is provided.
|
||||
@@ -329,6 +330,16 @@ unfixable = []
|
||||
# Allow unused variables when underscore-prefixed.
|
||||
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
||||
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
"scripts/*" = ["TID251"]
|
||||
"setup.py" = ["TID251"]
|
||||
"superset/config.py" = ["TID251"]
|
||||
"superset/cli/update.py" = ["TID251"]
|
||||
"superset/key_value/types.py" = ["TID251"]
|
||||
"superset/translations/utils.py" = ["TID251"]
|
||||
"superset/extensions/__init__.py" = ["TID251"]
|
||||
"superset/utils/json.py" = ["TID251"]
|
||||
|
||||
[tool.ruff.lint.isort]
|
||||
case-sensitive = false
|
||||
combine-as-imports = true
|
||||
@@ -345,6 +356,9 @@ section-order = [
|
||||
"local-folder"
|
||||
]
|
||||
|
||||
[tool.ruff.lint.flake8-tidy-imports]
|
||||
banned-api = { json = { msg = "Use superset.utils.json instead" }, simplejson = { msg = "Use superset.utils.json instead" } }
|
||||
|
||||
[tool.ruff.format]
|
||||
# Like Black, use double quotes for strings.
|
||||
quote-style = "double"
|
||||
|
||||
@@ -23,7 +23,7 @@ from superset import db
|
||||
from superset.sql.parse import Table
|
||||
from superset.utils import json
|
||||
|
||||
from ..utils.database import get_example_database
|
||||
from ..utils.database import get_example_database # noqa: TID252
|
||||
from .helpers import get_table_connector_registry, read_example_data
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -31,7 +31,7 @@ from superset.sql.parse import Table
|
||||
from superset.utils import json
|
||||
from superset.utils.core import DatasourceType
|
||||
|
||||
from ..utils.database import get_example_database
|
||||
from ..utils.database import get_example_database # noqa: TID252
|
||||
from .helpers import (
|
||||
get_slice_json,
|
||||
get_table_connector_registry,
|
||||
|
||||
@@ -25,7 +25,7 @@ from superset.models.slice import Slice
|
||||
from superset.sql.parse import Table
|
||||
from superset.utils.core import DatasourceType
|
||||
|
||||
from ..utils.database import get_example_database
|
||||
from ..utils.database import get_example_database # noqa: TID252
|
||||
from .helpers import (
|
||||
get_slice_json,
|
||||
get_table_connector_registry,
|
||||
|
||||
@@ -28,7 +28,7 @@ from superset.sql.parse import Table
|
||||
from superset.utils import json
|
||||
from superset.utils.core import DatasourceType
|
||||
|
||||
from ..utils.database import get_example_database
|
||||
from ..utils.database import get_example_database # noqa: TID252
|
||||
from .helpers import (
|
||||
get_slice_json,
|
||||
get_table_connector_registry,
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from astroid import nodes
|
||||
@@ -22,41 +21,6 @@ from pylint.checkers import BaseChecker
|
||||
from pylint.lint import PyLinter
|
||||
|
||||
|
||||
class JSONLibraryImportChecker(BaseChecker):
|
||||
name = "disallowed-json-import"
|
||||
priority = -1
|
||||
msgs = {
|
||||
"C9001": (
|
||||
"Disallowed json import used, use superset.utils.json instead",
|
||||
"disallowed-json-import",
|
||||
"Used when a disallowed import is used in a specific file.",
|
||||
),
|
||||
}
|
||||
exclude_files = [
|
||||
"setup.py",
|
||||
"superset/utils/json.py",
|
||||
"superset/config.py",
|
||||
"superset/cli/update.py",
|
||||
"superset/key_value/types.py",
|
||||
"superset/translations/utils.py",
|
||||
"superset/extensions/__init__.py",
|
||||
]
|
||||
path_strip_prefix = os.getcwd() + os.sep
|
||||
|
||||
def visit_import(self, node: nodes.Import) -> None:
|
||||
file = (node.root().file).replace(self.path_strip_prefix, "", 1)
|
||||
if file not in self.exclude_files:
|
||||
for module_name, _ in node.names:
|
||||
if module_name in ["json", "simplejson"]:
|
||||
self.add_message("disallowed-json-import", node=node)
|
||||
|
||||
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
|
||||
file = (node.root().file).replace(self.path_strip_prefix, "", 1)
|
||||
if file not in self.exclude_files:
|
||||
if node.modname in ["json", "simplejson"]:
|
||||
self.add_message("disallowed-json-import", node=node)
|
||||
|
||||
|
||||
class TransactionChecker(BaseChecker):
|
||||
name = "consider-using-transaction"
|
||||
msgs = {
|
||||
@@ -113,6 +77,5 @@ class SQLParsingLibraryImportChecker(BaseChecker):
|
||||
|
||||
|
||||
def register(linter: PyLinter) -> None:
|
||||
linter.register_checker(JSONLibraryImportChecker(linter))
|
||||
linter.register_checker(SQLParsingLibraryImportChecker(linter))
|
||||
linter.register_checker(TransactionChecker(linter))
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import json
|
||||
import json # noqa: TID251
|
||||
import math
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
@@ -22,7 +22,7 @@ Create Date: 2025-06-06 00:39:00.107746
|
||||
|
||||
"""
|
||||
|
||||
import json
|
||||
import json # noqa: TID251
|
||||
import logging
|
||||
|
||||
from alembic import op
|
||||
|
||||
@@ -34,15 +34,15 @@ from superset.utils.database import get_example_database
|
||||
from tests.integration_tests.base_tests import SupersetTestCase
|
||||
from tests.integration_tests.test_app import app
|
||||
|
||||
from ..fixtures.birth_names_dashboard import (
|
||||
from ..fixtures.birth_names_dashboard import ( # noqa: TID252
|
||||
load_birth_names_dashboard_with_slices, # noqa: F401
|
||||
load_birth_names_data, # noqa: F401
|
||||
)
|
||||
from ..fixtures.energy_dashboard import (
|
||||
from ..fixtures.energy_dashboard import ( # noqa: TID252
|
||||
load_energy_table_data, # noqa: F401
|
||||
load_energy_table_with_slice, # noqa: F401
|
||||
)
|
||||
from ..fixtures.pyodbcRow import Row
|
||||
from ..fixtures.pyodbcRow import Row # noqa: TID252
|
||||
|
||||
|
||||
class SupersetTestCases(SupersetTestCase):
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import json
|
||||
import json # noqa: TID251
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import json
|
||||
import json # noqa: TID251
|
||||
from collections.abc import Iterator
|
||||
from typing import Any
|
||||
from uuid import uuid3
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
import json
|
||||
import json # noqa: TID251
|
||||
from typing import Any
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import json # noqa: TID251
|
||||
from datetime import datetime
|
||||
from unittest.mock import patch
|
||||
from uuid import UUID
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import json # noqa: TID251
|
||||
from textwrap import dedent
|
||||
from typing import Any
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import json # noqa: TID251
|
||||
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
# pylint: disable=invalid-name, unused-argument, redefined-outer-name
|
||||
|
||||
import json
|
||||
import json # noqa: TID251
|
||||
|
||||
import pytest
|
||||
from flask_appbuilder.security.sqla.models import Role, User
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
# under the License.
|
||||
# pylint: disable=import-outside-toplevel, invalid-name, unused-argument, too-many-locals
|
||||
|
||||
import json
|
||||
import json # noqa: TID251
|
||||
from unittest import mock
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
Reference in New Issue
Block a user