external.py (1852B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 import os 6 import time 7 8 from mozlint import result 9 from mozlint.errors import LintException 10 11 12 def badreturncode(files, config, **lintargs): 13 return 1 14 15 16 def external(files, config, **lintargs): 17 if lintargs.get("fix"): 18 # mimics no results because they got fixed 19 return [] 20 21 results = [] 22 for path in files: 23 if os.path.isdir(path): 24 continue 25 26 with open(path) as fh: 27 for i, line in enumerate(fh.readlines()): 28 if "foobar" in line: 29 results.append( 30 result.from_config( 31 config, path=path, lineno=i + 1, column=1, rule="no-foobar" 32 ) 33 ) 34 return results 35 36 37 def raises(files, config, **lintargs): 38 raise LintException("Oh no something bad happened!") 39 40 41 def slow(files, config, **lintargs): 42 time.sleep(2) 43 return [] 44 45 46 def structured(files, config, logger, **kwargs): 47 for path in files: 48 if os.path.isdir(path): 49 continue 50 51 with open(path) as fh: 52 for i, line in enumerate(fh.readlines()): 53 if "foobar" in line: 54 logger.lint_error( 55 path=path, lineno=i + 1, column=1, rule="no-foobar" 56 ) 57 58 59 def passes(files, config, **lintargs): 60 return [] 61 62 63 def setup(**lintargs): 64 print("setup passed") 65 66 67 def setupfailed(**lintargs): 68 print("setup failed") 69 return 1 70 71 72 def setupraised(**lintargs): 73 print("setup raised") 74 raise LintException("oh no setup failed") 75 76 77 def setupskipped(**lintargs): 78 print("setup skipped") 79 return -1