mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Lint json files
This commit is contained in:
parent
21f0e63979
commit
a9c8f592a9
1 changed files with 20 additions and 4 deletions
|
@ -15,14 +15,18 @@ import StringIO
|
||||||
import site
|
import site
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
from licenseck import licenses
|
from licenseck import licenses
|
||||||
|
|
||||||
filetypes_to_check = [".rs", ".rc", ".cpp", ".c", ".h", ".lock", ".py", ".toml", ".webidl"]
|
filetypes_to_check = [".rs", ".rc", ".cpp", ".c", ".h", ".lock", ".py", ".toml", ".webidl", ".json"]
|
||||||
|
|
||||||
ignored_files = [
|
ignored_files = [
|
||||||
# Generated and upstream code combined with our own. Could use cleanup
|
# Generated and upstream code combined with our own. Could use cleanup
|
||||||
os.path.join(".", "ports", "gonk", "src", "native_window_glue.cpp"),
|
os.path.join(".", "ports", "gonk", "src", "native_window_glue.cpp"),
|
||||||
os.path.join(".", "ports", "geckolib", "bindings.rs"),
|
os.path.join(".", "ports", "geckolib", "bindings.rs"),
|
||||||
|
os.path.join(".", "resources", "hsts_preload.json"),
|
||||||
|
os.path.join(".", "tests", "wpt", "metadata", "MANIFEST.json"),
|
||||||
|
os.path.join(".", "tests", "wpt", "metadata-css", "MANIFEST.json"),
|
||||||
# MIT license
|
# MIT license
|
||||||
os.path.join(".", "components", "util", "deque", "mod.rs"),
|
os.path.join(".", "components", "util", "deque", "mod.rs"),
|
||||||
# Hidden files
|
# Hidden files
|
||||||
|
@ -81,7 +85,7 @@ MAX_LICENSE_LINESPAN = max(len(license.splitlines()) for license in licenses)
|
||||||
|
|
||||||
|
|
||||||
def check_license(file_name, lines):
|
def check_license(file_name, lines):
|
||||||
if file_name.endswith(".toml") or file_name.endswith(".lock"):
|
if any(file_name.endswith(ext) for ext in (".toml", ".lock", ".json")):
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
while lines and (lines[0].startswith(EMACS_HEADER) or lines[0].startswith(VIM_HEADER)):
|
while lines and (lines[0].startswith(EMACS_HEADER) or lines[0].startswith(VIM_HEADER)):
|
||||||
lines = lines[1:]
|
lines = lines[1:]
|
||||||
|
@ -93,7 +97,7 @@ def check_license(file_name, lines):
|
||||||
|
|
||||||
|
|
||||||
def check_length(file_name, idx, line):
|
def check_length(file_name, idx, line):
|
||||||
if file_name.endswith(".lock"):
|
if file_name.endswith(".lock") or file_name.endswith(".json"):
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
max_length = 120
|
max_length = 120
|
||||||
if len(line.rstrip('\n')) > max_length:
|
if len(line.rstrip('\n')) > max_length:
|
||||||
|
@ -469,6 +473,18 @@ def check_webidl_spec(file_name, contents):
|
||||||
yield 0, "No specification link found."
|
yield 0, "No specification link found."
|
||||||
|
|
||||||
|
|
||||||
|
def check_json(filename, contents):
|
||||||
|
if not filename.endswith(".json"):
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
|
try:
|
||||||
|
json.loads(contents)
|
||||||
|
except ValueError as e:
|
||||||
|
match = re.search(r"line (\d+) ", e.message)
|
||||||
|
line_no = match and match.group(1)
|
||||||
|
yield (line_no, e.message)
|
||||||
|
|
||||||
|
|
||||||
def check_spec(file_name, lines):
|
def check_spec(file_name, lines):
|
||||||
base_path = "components/script/dom/"
|
base_path = "components/script/dom/"
|
||||||
if base_path not in file_name:
|
if base_path not in file_name:
|
||||||
|
@ -573,7 +589,7 @@ def get_file_list(directory, only_changed_files=False, exclude_dirs=[]):
|
||||||
def scan(faster=False, progress=True):
|
def scan(faster=False, progress=True):
|
||||||
# standard checks
|
# standard checks
|
||||||
files_to_check = filter_files('.', faster, progress)
|
files_to_check = filter_files('.', faster, progress)
|
||||||
checking_functions = (check_flake8, check_lock, check_webidl_spec)
|
checking_functions = (check_flake8, check_lock, check_webidl_spec, check_json)
|
||||||
line_checking_functions = (check_license, check_by_line, check_toml, check_rust, check_spec)
|
line_checking_functions = (check_license, check_by_line, check_toml, check_rust, check_spec)
|
||||||
errors = collect_errors_for_files(files_to_check, checking_functions, line_checking_functions)
|
errors = collect_errors_for_files(files_to_check, checking_functions, line_checking_functions)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue