-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1055 from klmcadams/feat/lint-file
feat: lint-file subcommand
- Loading branch information
Showing
24 changed files
with
842 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Add lint-file subcommand to enable running lint on specific files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.. | ||
SPDX-FileCopyrightText: 2019 Free Software Foundation Europe e.V. <https://fsfe.org> | ||
SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com> | ||
SPDX-License-Identifier: CC-BY-SA-4.0 | ||
|
||
reuse-lint-file | ||
=============== | ||
|
||
Synopsis | ||
-------- | ||
|
||
**reuse lint-file** [*options*] [*file* ...] | ||
|
||
Description | ||
----------- | ||
|
||
:program:`reuse-lint-file` verifies whether the specified files are compliant | ||
with the REUSE Specification located at `<https://reuse.software/spec>`_. It | ||
runs the linter from :manpage:`reuse-lint(1)` against a subset of files, using a | ||
subset of criteria. | ||
|
||
Files that are ignored by :program:`reuse-lint` are also ignored by | ||
:program:`reuse-lint-file`, even if specified. | ||
|
||
Criteria | ||
-------- | ||
|
||
The criteria are the same as used in :manpage:`reuse-lint(1)`, but using only a | ||
subset: | ||
|
||
- Missing licenses. | ||
- Read errors. | ||
- Files without copyright and license information. | ||
|
||
Options | ||
------- | ||
|
||
.. option:: -q, --quiet | ||
|
||
Do not print anything to STDOUT. | ||
|
||
.. option:: -l, --lines | ||
|
||
Output one line per error, prefixed by the file path. This option is the | ||
default. | ||
|
||
.. option:: -h, --help | ||
|
||
Display help and exit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# SPDX-FileCopyrightText: 2024 Kerry McAdams <github@klmcadams> | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
"""Linting specific files happens here. The linting here is nothing more than | ||
reading the reports and printing some conclusions. | ||
""" | ||
|
||
import sys | ||
from argparse import ArgumentParser, Namespace | ||
from gettext import gettext as _ | ||
from pathlib import Path | ||
from typing import IO | ||
|
||
from ._util import PathType, is_relative_to | ||
from .lint import format_lines_subset | ||
from .project import Project | ||
from .report import ProjectSubsetReport | ||
|
||
|
||
def add_arguments(parser: ArgumentParser) -> None: | ||
"""Add arguments to parser.""" | ||
mutex_group = parser.add_mutually_exclusive_group() | ||
mutex_group.add_argument( | ||
"-q", "--quiet", action="store_true", help=_("prevents output") | ||
) | ||
mutex_group.add_argument( | ||
"-l", | ||
"--lines", | ||
action="store_true", | ||
help=_("formats output as errors per line (default)"), | ||
) | ||
parser.add_argument( | ||
"files", | ||
action="store", | ||
nargs="*", | ||
type=PathType("r"), | ||
help=_("files to lint"), | ||
) | ||
|
||
|
||
def run(args: Namespace, project: Project, out: IO[str] = sys.stdout) -> int: | ||
"""List all non-compliant files from specified file list.""" | ||
subset_files = {Path(file_) for file_ in args.files} | ||
for file_ in subset_files: | ||
if not is_relative_to(file_.resolve(), project.root.resolve()): | ||
args.parser.error( | ||
_("'{file}' is not inside of '{root}'").format( | ||
file=file_, root=project.root | ||
) | ||
) | ||
report = ProjectSubsetReport.generate( | ||
project, | ||
subset_files, | ||
multiprocessing=not args.no_multiprocessing, | ||
) | ||
|
||
if args.quiet: | ||
pass | ||
else: | ||
out.write(format_lines_subset(report)) | ||
|
||
return 0 if report.is_compliant else 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.