from __future__ import unicode_literals
import abc
import os
import re
import six
MYPY = False
if MYPY:
# MYPY is set to True when run under Mypy.
from typing import List, Optional, Pattern, Text, Match
class Rule(six.with_metaclass(abc.ABCMeta)):
@abc.abstractproperty
def name(self):
# type: () -> Text
pass
@abc.abstractproperty
def description(self):
# type: () -> Text
pass
to_fix = None # type: Optional[Text]
@classmethod
def error(cls, path, context=(), line_no=None):
description = cls.description % context
return (cls.name, description, path, line_no)
class MissingLink(Rule):
name = "MISSING-LINK"
description = "Testcase file must have a link to a spec"
to_fix = """
Ensure that there is a `` for the spec.
`MISSING-LINK` is designed to ensure that the CSS build tool can find
the tests. Note that the CSS build system is primarily used by
[test.csswg.org/](http://test.csswg.org/), which doesn't use
`wptserve`, so `*.any.js` and similar tests won't work there; stick
with the `.html` equivalent.
"""
class PathLength(Rule):
name = "PATH LENGTH"
description = "/%s longer than maximum path length (%d > 150)"
class WorkerCollision(Rule):
name = "WORKER COLLISION"
description = ("path ends with %s which collides with generated tests "
"from %s files")
class GitIgnoreFile(Rule):
name = "GITIGNORE"
description = ".gitignore found outside the root"
class AhemCopy(Rule):
name = "AHEM COPY"
description = "Don't add extra copies of Ahem, use /fonts/Ahem.ttf"
# TODO: Add tests for this rule
class IgnoredPath(Rule):
name = "IGNORED PATH"
description = ("%s matches an ignore filter in .gitignore - "
"please add a .gitignore exception")
class CSSCollidingTestName(Rule):
name = "CSS-COLLIDING-TEST-NAME"
description = "The filename %s in the %s testsuite is shared by: %s"
class CSSCollidingRefName(Rule):
name = "CSS-COLLIDING-REF-NAME"
description = "The filename %s is shared by: %s"
class CSSCollidingSupportName(Rule):
name = "CSS-COLLIDING-SUPPORT-NAME"
description = "The filename %s is shared by: %s"
class SupportWrongDir(Rule):
name = "SUPPORT-WRONG-DIR"
description = "Support file not in support directory"
class ParseFailed(Rule):
name = "PARSE-FAILED"
description = "Unable to parse file"
class ContentManual(Rule):
name = "CONTENT-MANUAL"
description = "Manual test whose filename doesn't end in '-manual'"
class ContentVisual(Rule):
name = "CONTENT-VISUAL"
description = "Visual test whose filename doesn't end in '-visual'"
class AbsoluteUrlRef(Rule):
name = "ABSOLUTE-URL-REF"
description = ("Reference test with a reference file specified via an "
"absolute URL: '%s'")
class SameFileRef(Rule):
name = "SAME-FILE-REF"
description = "Reference test which points at itself as a reference"
class NonexistentRef(Rule):
name = "NON-EXISTENT-REF"
description = ("Reference test with a non-existent '%s' relationship "
"reference: '%s'")
class MultipleTimeout(Rule):
name = "MULTIPLE-TIMEOUT"
description = "More than one meta name='timeout'"
class InvalidTimeout(Rule):
name = "INVALID-TIMEOUT"
description = "Invalid timeout value %s"
class MultipleTestharness(Rule):
name = "MULTIPLE-TESTHARNESS"
description = "More than one