Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add docs
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Abraham <[email protected]>
jabraham17 committed Dec 12, 2024
1 parent 82da456 commit eee7400
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions doc/rst/tools/chplcheck/chplcheck.rst
Original file line number Diff line number Diff line change
@@ -248,6 +248,27 @@ This function performs _two_ pattern-based searches: one for formals, and one
for identifiers that might reference the formals. It then emits a warning for
each formal for which there wasn't a corresponding identifier.

Location Rules
~~~~~~~~~~~~~~

Sometimes, a linter rule is not based on a pattern of AST nodes, but rather on a
textual pattern in the source code. For example, a rule might check that all lines
in a file are indented with spaces, not tabs. To support this, ``chplcheck`` has
a third type of rule: location rules. These rules are specified using the
``driver.location_rule`` decorator. Location rules yield a ``RuleLocation`` object that specifies the textual location of the issue. A ``RuleLocation`` has a path, a start position, and an end position. The start and end positions are tuples of line and column numbers, where the first character in the file is at line 1, column 1.

Alternatively, a location rule can yield ``LocationRuleResult`` objects wraps a ``RuleLocation`` object along with other data, like fixits.

The following example demonstrates a rule that location rule that checks for tabs:

.. code-block:: python
@driver.location_rule
def NoTabs(context: chapel.Context, path: str, lines: List[str])
for line, text in enumerate(lines, start=1):
if '\t' in text:
yield RuleLocation(line, (i, 1), (i, len(line) + 1))
Making Rules Ignorable
~~~~~~~~~~~~~~~~~~~~~~

0 comments on commit eee7400

Please sign in to comment.