Skip to content

Commit

Permalink
Move linting to tools module
Browse files Browse the repository at this point in the history
  • Loading branch information
suchow committed Apr 4, 2016
1 parent 1040ba7 commit bdfc313
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 36 deletions.
37 changes: 1 addition & 36 deletions proselint/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
import click
import os
from .tools import (
line_and_column,
is_quoted,
close_cache_shelves_after,
close_cache_shelves,
get_checks,
errors_to_json,
lint,
)
import subprocess
import json
import sys
from .score import score as lintscore
from .version import __version__
Expand All @@ -30,38 +27,6 @@
demo_file = os.path.join(proselint_path, "demo.md")


def lint(input_file, debug=False):
"""Run the linter on the input file."""
# Load the options.
options = json.load(open(os.path.join(proselint_path, '.proselintrc')))

checks = get_checks()

# Apply all the checks.
text = input_file.read()
errors = []
for check in checks:
if debug:
click.echo(check.__module__ + "." + check.__name__)

result = check(text)

for error in result:
(start, end, check, message) = error
(line, column) = line_and_column(text, start)
if not is_quoted(start, text):
errors += [(check, message, line, column, start, end,
end - start, "warning", None)]

if len(errors) > options["max_errors"]:
break

# Sort the errors by line and column number.
errors = sorted(errors[:options["max_errors"]])

return errors


def timing_test(corpus="0.1.0"):
"""Measure timing performance on the named corpus."""
import time
Expand Down
27 changes: 27 additions & 0 deletions proselint/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,33 @@ def line_and_column(text, position):
position_counter += len(line)


def lint(input_file, debug=False):
"""Run the linter on the input file."""
checks = get_checks()

# Apply all the checks.
text = input_file.read()
errors = []
for check in checks:

result = check(text)

for error in result:
(start, end, check, message) = error
(line, column) = line_and_column(text, start)
if not is_quoted(start, text):
errors += [(check, message, line, column, start, end,
end - start, "warning", None)]

if len(errors) > options["max_errors"]:
break

# Sort the errors by line and column number.
errors = sorted(errors[:options["max_errors"]])

return errors


def consistency_check(text, word_pairs, err, msg, offset=0):
"""Build a consistency checker for the given word_pairs."""
errors = []
Expand Down

0 comments on commit bdfc313

Please sign in to comment.