extend = "pyproject.toml"
lint.ignore = [
    # NOTE: to find a good code to fix, run:
    # ruff check --select="ALL" --statistics astropy/<subpackage>

    # flake8-annotations (ANN) : static typing
    "ANN001",  # Function argument without type annotation
    "ANN003",  # `**kwargs` without type annotation
    "ANN202",  # Private function without return type annotation
    "ANN401",  # Use of `Any` type

    # flake8-unused-arguments (ARG)
    "ARG001",  # unused-function-argument
    "ARG002",  # unused-method-argument
    "ARG003",  # unused-class-method-argument
    "ARG004",  # unused-static-method-argument
    "ARG005",  # unused-lambda-argument

    # flake8-bugbear (B)
    "B006",  # MutableArgumentDefault
    "B023",  # FunctionUsesLoopVariable
    "B028",  # No-explicit-stacklevel
    "B904",  # RaiseWithoutFromInsideExcept
    "B905",  # ZipWithoutExplicitStrict

    # flake8-blind-except (BLE)
    "BLE001",  # blind-except

    # mccabe (C90) : code complexity
    # TODO: configure maximum allowed complexity.
    "C901",  # McCabeComplexity

    # pydocstyle (D)
    # Missing Docstrings
    "D100",  # undocumented-public-module
    "D101",  # undocumented-public-class
    "D103",  # undocumented-public-function
    "D104",  # undocumented-public-package
    "D205",  # blank-line-after-summary
    # Quotes Issues
    "D301",  # escape-sequence-in-docstring
    # Docstring Content Issues
    "D403",  # first-line-capitalized
    "D404",  # docstring-starts-with-this
    "D401",  # non-imperative-mood.
    "D414",  # empty-docstring-section
    "D419",  # docstring is empty

    # flake8-datetimez (DTZ)
    "DTZ001",  # call-datetime-without-tzinfo
    "DTZ005",  # call-datetime-now-without-tzinfo

    # pycodestyle (E, W)
    "E501",  # line-too-long
    "E721",  # type-comparison
    "E731",  # lambda-assignment

    # flake8-errmsg (EM)  : nicer error tracebacks
    "EM101",   # raw-string-in-exception
    "EM102",   # f-string-in-exception
    "EM103",   # dot-format-in-exception

    # eradicate (ERA)
    # NOTE: be careful that developer notes are kept.
    "ERA001",  # commented-out-code

    # Pyflakes (F)
    "F841",  # unused-variable

    # flake8-boolean-trap (FBT)  : boolean flags should be kwargs, not args
    # NOTE: a good thing to fix, but changes API.
    "FBT001",  # boolean-positional-arg-in-function-definition
    "FBT002",  # boolean-default-value-in-function-definition
    "FBT003",  # boolean-positional-value-in-function-call

    # flake8-fixme (FIX)
    "FIX001",  # Line contains FIXME.  this should be fixed or at least FIXME replaced with TODO
    "FIX004",  # Line contains HACK. replace HACK with NOTE.

    "FURB166",  # int-on-sliced-str

    # pep8-naming (N)
    # NOTE: some of these can/should be fixed, but this changes the API.
    "N801",  # invalid-class-name
    "N802",  # invalid-function-name
    "N803",  # invalid-argument-name
    "N805",  # invalid-first-argument-name-for-method
    "N807",  # dunder-function-name
    "N813",  # camelcase-imported-as-lowercase
    "N815",  # mixed-case-variable-in-class-scope
    "N816",  # mixed-case-variable-in-global-scope
    "N818",  # error-suffix-on-exception-name

    # NumPy-specific rules (NPY)
    "NPY002", # Replace legacy `np.random.rand` call with `np.random.Generator`  (2023-05-03)

    # Perflint (PERF)
    "PERF203",  # `try`-`except` within a loop incurs performance overhead
    "PERF401",  # Use a list comprehension to create a transformed list

    # Pylint (PLC, PLE, PLR, PLW)
    "PLR0124",  # Name compared with itself
    "PLR0402",  # ConsiderUsingFromImport
    "PLR0912",  # too-many-branches
    "PLR0913",  # too-many-args
    "PLR0915",  # too-many-statements
    "PLR1714",  # Consider merging multiple comparisons
    "PLR2004",  # MagicValueComparison
    "PLR5501",  # collapsible-else-if
    "PLW0603",  # global-statement
    "PLW1641",  # Object does not implement `__hash__` method
    "PLW2901",  # redefined-loop-name

    # flake8-pytest-style (PT)
    "PT003",   # pytest-extraneous-scope-function
    "PT006",   # pytest-parametrize-names-wrong-type
    "PT007",   # pytest-parametrize-values-wrong-type
    "PT011",   # pytest-raises-too-broad
    "PT012",   # pytest-raises-with-multiple-statements
    "PT017",   # pytest-assert-in-exceptinstead
    "PT018",   # pytest-composite-assertion
    "PT028",   # pytest-parameter-with-default-argument
    "PT030",   # pytest.warns({warning}) is too broad

    # flake8-return (RET)
    "RET501",  # unnecessary-return-none
    "RET502",  # implicit-return-value
    "RET503",  # implicit-return
    "RET507",  # superfluous-else-continue

    # flake8-raise (RSE)
    "RSE102",  # unnecessary-paren-on-raise-exception

    # Ruff-specific rules (RUF)
    "RUF001",  # ambiguous-unicode-character-string
    "RUF002",  # ambiguous-unicode-character-docstring
    "RUF010",  # use conversion in f-string
    "RUF012",  # Mutable class attributes should be annotated with `typing.ClassVar`
    "RUF043",  # pytest-raises-ambiguous-pattern
    "RUF059",  # unused-unpacked-variable

    # flake8-bandit (S)
    "S101",  # Use of `assert` detected
    "S105",  # hardcoded-password-string
    "S110",  # try-except-pass
    "S112",  # try-except-continue
    "S301",  # suspicious-pickle-usage
    "S307",  # Use of possibly insecure function; consider using `ast.literal_eval`
    "S311",  # suspicious-non-cryptographic-randomness
    "S324",  # hashlib-insecure-hash-function
    "S506",  # UnsafeYAMLLoad
    "S310",  # Suspicious-url-open-usage
    "S603",  # `subprocess` call: check for execution of untrusted input
    "S607",  # Starting a process with a partial executable path

    # flake8-simplify (SIM)
    "SIM102",  # NestedIfStatements
    "SIM105",  # UseContextlibSuppress
    "SIM108",  # UseTernaryOperator
    "SIM114",  # if-with-same-arms
    "SIM115",  # OpenFileWithContextHandler
    "SIM117",  # MultipleWithStatements
    "SIM118",  # KeyInDict
    "SIM201",  # NegateEqualOp
    "SIM300",  # yoda condition

    # flake8-print (T20)
    "T201",  # PrintUsed

    # flake8-todos (TD)
    "TD001",  # Invalid TODO tag
    "TD003",  # Missing issue link on the line following this TODO
    "TD004",  # Missing colon in TODO
    "TD007",  # Missing space after colon in TODO

    # tryceratops (TRY)
    "TRY002",  # raise-vanilla-class
    "TRY003",  # raise-vanilla-args
    "TRY004",  # prefer-type-error
    "TRY201",  # verbose-raise
    "TRY301",  # raise-within-try
]
lint.unfixable = [
    "E711"  # NoneComparison. Hard to fix b/c numpy has it's own None.
]

[lint.extend-per-file-ignores]
"__init__.py" = [
    "F401",
    "PLC0415",  # import-outside-top-level
]
"conftest.py" = [
    "PLC0415",  # import-outside-top-level
]
"test_*.py" = [
    "PTH", # all flake8-use-pathlib
    "RUF015",  # Prefer next({iterable}) over single element slice
]
# TODO: fix these, on a per-subpackage basis.
# When a general exclusion is being fixed, but it affects many subpackages, it
# is better to fix for subpackages individually. The general exclusion should be
# copied to these subpackage sections and fixed there.
"astropy/**/setup_package.py" = [
    # all flake8-use-pathlib
    # reason: subtle differences between pathlib.Path.relative_to and os.path.relpath
    "PTH",
]
"astropy/config/*" = [
    "PLC0415",  # import-outside-top-level
    "PT031",  # pytest-warns-with-multiple-statements
]
"astropy/constants/*" = [
    "PLC0415",  # import-outside-top-level
]
"astropy/convolution/*" = [
    "PLC0415",  # import-outside-top-level
    "PT031",  # pytest-warns-with-multiple-statements
]
"astropy/coordinates/*" = [
    "PLC0415",  # import-outside-top-level
    "PT031",  # pytest-warns-with-multiple-statements
    "PTH",     # all flake8-use-pathlib
    "DTZ007",  # call-datetime-strptime-without-zone
]
"astropy/cosmology/*" = [
    "PLC0415",  # import-outside-top-level
    "PT019",   # pytest-fixture-param-without-value
    "PT031",  # pytest-warns-with-multiple-statements
]
"astropy/io/*" = [
    "G001",  # logging-string-format
    "G004",  # logging-f-string
    "PLR0911",  # too-many-return-statements
    "PTH116",  # os-stat
    "PTH117",  # os-path-isabs
    "S314",  # defusedxml
    "SLOT000",  # Subclasses of `str` should define `__slots__`
    "TD005",  # Missing issue description after `TODO`
    "TRY400",  # error-instead-of-exception
    "TRY300",  # Consider `else` block
]
"astropy/io/ascii/*" = [
    "B007",  # UnusedLoopControlVariable
    "PLC0415",  # import-outside-top-level
    "PT031",  # pytest-warns-with-multiple-statements
]
"astropy/io/fits/*" = [
    "B007",  # UnusedLoopControlVariable
    "PLC0415",  # import-outside-top-level
    "PT031",  # pytest-warns-with-multiple-statements
    "PTH",
]
"astropy/io/misc/*" = [
    "B007",  # UnusedLoopControlVariable
    "PLC0415",  # import-outside-top-level
    "PT031",  # pytest-warns-with-multiple-statements
]
"astropy/io/registry/*" = [
    "PLC0415",  # import-outside-top-level
    "PTH",
]
"astropy/io/votable/*" = [
    "B007",  # UnusedLoopControlVariable
    "PLC0415",  # import-outside-top-level
    "PT031",  # pytest-warns-with-multiple-statements
    "PTH",
]
"astropy/logger.py" = [
    "PLC0415",  # import-outside-top-level
]
"astropy/modeling/*" = [
    "PLC0415",  # import-outside-top-level
    "PLR0911",  # too-many-return-statements
    "RET504",  # unnecessary-assign
    "SLOT001",  # Subclasses of `tuple` should define `__slots__`
    "TRY300",  # Consider `else` block
    "F811",  # see https://github.com/astropy/astropy/pull/16633
]
"astropy/nddata/*" = [
    "PLC0415",  # import-outside-top-level
]
"astropy/samp/*" = [
    "PLC0415",  # import-outside-top-level
    "PTH",      # all flake8-use-pathlib
    "RET504",  # unnecessary-assign
]
"astropy/stats/*" = [
    "B007",  # UnusedLoopControlVariable
    "PLC0415",  # import-outside-top-level
    "PLR0911",  # too-many-return-statements
    "PT031",  # pytest-warns-with-multiple-statements
    "RET504",  # unnecessary-assign
]
"astropy/table/*" = [
    "PLC0415",  # import-outside-top-level
    "PT031",  # pytest-warns-with-multiple-statements
    "RET504",  # unnecessary-assign
    "S605",  # Starting a process with a shell, possible injection detected
    "TRY300",  # Consider `else` block
]
"astropy/tests/*" = [
    "PLC0415",  # import-outside-top-level
    "PT031",  # pytest-warns-with-multiple-statements
    "PTH",      # all flake8-use-pathlib
]
"astropy/time/*" = [
    "FIX003",  # Line contains XXX.  replace XXX with TODO
    "PIE794",  # duplicate-class-field-definition
    "PLC0415",  # import-outside-top-level
    "PT031",  # pytest-warns-with-multiple-statements
    "RET504",  # unnecessary-assign
]
"astropy/timeseries/*" = [
    "PLC0415",  # import-outside-top-level
    "PLR0911",  # too-many-return-statements
    "PT031",  # pytest-warns-with-multiple-statements
    "RET504",  # unnecessary-assign
]
"astropy/units/*" = [
    "N812",  # lowercase-imported-as-non-lowercase
    "PLC0415",  # import-outside-top-level
    "PLR0911",  # too-many-return-statements
    "PT031",  # pytest-warns-with-multiple-statements
    "RET504",  # unnecessary-assign
    "TRY300",  # Consider `else` block
]
"astropy/uncertainty/*" = [
    "PLC0415",  # import-outside-top-level
]
"astropy/utils/*" = [
    "B007",  # UnusedLoopControlVariable
    "N811",  # constant-imported-as-non-constant
    "PLC0415",  # import-outside-top-level
    "PLR0911",  # too-many-return-statements
    "PT031",  # pytest-warns-with-multiple-statements
    "PTH",      # all flake8-use-pathlib
    "RET504",  # unnecessary-assign
    "S321",  # Suspicious-ftp-lib-usage
    "TRY300",  # Consider `else` block
]
"astropy/visualization/*" = [
    "B015",
    "PLC0415",  # import-outside-top-level
    "PLR0911",  # too-many-return-statements
]
"astropy/wcs/*" = [
    "F821",  # undefined-name
    "PLC0415",  # import-outside-top-level
    "PT031",  # pytest-warns-with-multiple-statements
    "PTH",      # all flake8-use-pathlib
    "RET504",  # unnecessary-assign
    "S608",  # Posslibe SQL injection
    "SIM202",  # NegateNotEqualOp
    "TRY300",  # Consider `else` block
]
"docs/*" = []

".pyinstaller/*.py" = ["PTH"]


[lint.flake8-import-conventions.aliases]
# xml is hardly ever used thus the alias should not be mandated
# There is no way to remove from the default list, only to override
# the default thus we list the things here that we actually should use.
"numpy" = "np"
"matplotlib" = "mpl"
"matplotlib.pyplot" = "plt"
