diff --git a/docs/code-quality/lint/create.rst b/docs/code-quality/lint/create.rst index 2efdf742f54c..4b2754175329 100644 --- a/docs/code-quality/lint/create.rst +++ b/docs/code-quality/lint/create.rst @@ -48,7 +48,7 @@ There are four types of linters, though more may be added in the future. As seen from the example above, string and regex linters are very easy to create, but they should be avoided if possible. It is much better to use a context aware linter for the language you -are trying to lint. For example, use eslint to lint JavaScript files, use flake8 to lint python +are trying to lint. For example, use eslint to lint JavaScript files, use ruff to lint Python files, etc. Which brings us to the third and most interesting type of linter, @@ -102,8 +102,8 @@ For structured_log lints the following additional keys apply: Example ------- -Here is an example of an external linter that shells out to the python flake8 linter, -let's call the file ``flake8_lint.py`` (`in-tree version `__): +Here is an example of an external linter that shells out to the Python ruff linter, +let's call the file ``ruff_lint.py`` (`in-tree version `__): .. code-block:: python @@ -116,63 +116,64 @@ let's call the file ``flake8_lint.py`` (`in-tree version `_ looks like the following snippet: +As an example, the `ruff test `_ looks like the following snippet: .. code-block:: python import mozunit - LINTER = 'flake8' + LINTER = 'ruff' - def test_lint_single_file(lint, paths): + def test_lint_ruff(lint, paths): results = lint(paths('bad.py')) assert len(results) == 2 assert results[0].rule == 'F401' @@ -233,7 +234,8 @@ As an example, the `Flake8 test `__): +path object format as an external payload. For example (`in-tree version `__): .. code-block:: yaml - flake8: + ruff: description: Python linter include: ['.'] extensions: ['py'] type: external - payload: py.flake8:lint - setup: py.flake8:setup + payload: py.ruff:lint + setup: py.ruff:setup The setup function takes a single argument, the root of the repository being -linted. In the case of ``flake8``, it might look like: +linted. In the case of ``ruff``, it might look like: .. code-block:: python import subprocess - from distutils.spawn import find_executable + from shutil import which def setup(root, **lintargs): # This is a simple example. Please look at the actual source for better examples. - if not find_executable('flake8'): - subprocess.call(['pip', 'install', 'flake8']) + if not which("ruff"): + subprocess.call(["pip", "install", "ruff"]) The setup function will be called implicitly before running the linter. This means it should return fast and not produce any output if there is no setup to @@ -341,28 +343,28 @@ First, the job will have to be declared in Taskcluster. This should be done in the `mozlint Taskcluster configuration `_. You will need to define a symbol, how it is executed and on what kind of change. -For example, for flake8, the configuration is the following: +For example, for ruff, the configuration is the following: .. code-block:: yaml - py-flake8: - description: flake8 run over the gecko codebase + py-ruff: + description: run ruff over the gecko codebase treeherder: - symbol: py(f8) + symbol: py(ruff) run: - mach: lint -l flake8 -f treeherder -f json:/builds/worker/mozlint.json + mach: lint -l ruff -f treeherder -f json:/builds/worker/mozlint.json . when: files-changed: - '**/*.py' - - '**/.flake8' - # moz.configure files are also Python files. - - '**/*.configure' + - '**/.ruff.toml' If the linter requires an external program, you will have to install it in the `setup script `_ and maybe install the necessary files in the `Docker configuration `_. .. note:: - If the defect found by the linter is minor, make sure that it is run as `tier 2 `_. - This prevents the tree from closing because of a tiny issue. - For example, the typo detection is run as tier-2. + If the defect found by the linter is minor, make sure that it is logged as + a warning by setting `{"level": "warning"}` in the + :class:`~mozlint.result.Issue`. This means the defect will not cause a + backout if landed, but will still be surfaced by reviewbot at review time, + or when using `-W/--warnings` locally.