SIMPLE-AstroDB / SIMPLE-db

BSD 3-Clause "New" or "Revised" License
11 stars 22 forks source link

Revisit linting for SIMPLE scripts/functions #543

Open dr-rodriguez opened 2 months ago

dr-rodriguez commented 2 months ago

We should add a linter step as part of our testing infrastructure for SIMPLE. I recommend using ruff with a toml file for handling settings. This is what I've used before as a run_lint.sh script:

#!/usr/bin/env bash

# Requires ruff in the current environment

# Summary
echo "Summary"
ruff check . --config=pyproject.toml --statistics

# To fix issues (eg, import sorting):
# ruff check . --config=pyproject.toml --statistics --fix

# Main invocation
echo "\nDetails"
ruff check . --config=pyproject.toml --exit-zero

where pyproject.toml contains something like:

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`)  codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
# See https://docs.astral.sh/ruff/rules/
select = ["E4", "E7", "E9", "F", "I", "PL", "C901", "RUF010"]
#select = ["ALL"]
ignore = ["PLR",  # pylint refactor
          "E701", # multiple statements on one line (revisit?)
          ]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

[tool.ruff]
line-length = 120
src = ["src"]
exclude = ["test"]

[tool.ruff.lint.mccabe]
# Flag errors (`C901`) whenever the complexity level exceeds this number.
max-complexity = 10
kelle commented 2 months ago

Would this just flag problems or also fix them?

I am more inclined to set this up in astrodb_utils since I think we should hold that code to a higher standard while I think of SIMPLE as more of a testbed.

I would also like to include instructions in our dev docs for adding this to ones VS Code setup.