[javascriptlint-commit] SF.net SVN: javascriptlint:[243] trunk
Status: Beta
Brought to you by:
matthiasmiller
From: <mat...@us...> - 2009-05-20 07:38:06
|
Revision: 243 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=243&view=rev Author: matthiasmiller Date: 2009-05-20 07:37:57 +0000 (Wed, 20 May 2009) Log Message: ----------- support the output-format setting Modified Paths: -------------- trunk/DEVELOPMENT trunk/jsl.py trunk/pyjsl/conf.py trunk/pyjsl/util.py Modified: trunk/DEVELOPMENT =================================================================== --- trunk/DEVELOPMENT 2009-03-04 07:19:18 UTC (rev 242) +++ trunk/DEVELOPMENT 2009-05-20 07:37:57 UTC (rev 243) @@ -20,7 +20,7 @@ Use the following command to upgrade SpiderMonkey. Replace X.X.X with the version number. js-X.X.X is the directory containing the new version of SpiderMonkey. Use a relative path for pretty commit messages. - + svn_load_dirs.pl \ -t X.X.X \ -p svn_load_dirs.conf \ Modified: trunk/jsl.py =================================================================== --- trunk/jsl.py 2009-03-04 07:19:18 UTC (rev 242) +++ trunk/jsl.py 2009-05-20 07:37:57 UTC (rev 243) @@ -57,7 +57,8 @@ def _lint(paths, conf): def lint_error(path, line, col, errname, errdesc): _lint_results['warnings'] = _lint_results['warnings'] + 1 - print '%s(%i): %s' % (path, line+1, errdesc) + print pyjsl.util.format_error(conf['output-format'], path, line, col, + errname, errdesc) pyjsl.lint.lint_files(paths, lint_error, conf=conf) def _resolve_paths(path, recurse): Modified: trunk/pyjsl/conf.py =================================================================== --- trunk/pyjsl/conf.py 2009-03-04 07:19:18 UTC (rev 242) +++ trunk/pyjsl/conf.py 2009-05-20 07:37:57 UTC (rev 243) @@ -55,7 +55,7 @@ self._settings = { 'recurse': recurse, 'show_context': BooleanSetting(False), - 'output-format': StringSetting('TODO'), + 'output-format': StringSetting('__FILE__(__LINE__): __ERROR__'), 'lambda_assign_requires_semicolon': BooleanSetting(False), 'legacy_control_comments': BooleanSetting(True), 'jscript_function_extensions': BooleanSetting(False), Modified: trunk/pyjsl/util.py =================================================================== --- trunk/pyjsl/util.py 2009-03-04 07:19:18 UTC (rev 242) +++ trunk/pyjsl/util.py 2009-05-20 07:37:57 UTC (rev 243) @@ -9,6 +9,46 @@ def isidentifier(text): return _identifier.match(text) +def _encode_error_keyword(s): + s = s.replace('\\', '\\\\') + s = s.replace('"', '\\"') + s = s.replace("'", "\\'") + s = s.replace("\t", "\\t") + s = s.replace("\r", "\\r") + s = s.replace("\n", "\\n") + return s + +def format_error(output_format, path, line, col, errname, errdesc): + errprefix = 'warning' #TODO + replacements = { + '__FILE__': path, + '__FILENAME__': os.path.basename(path), + '__LINE__': str(line+1), + '__COL__': str(col), + '__ERROR__': '%s: %s' % (errprefix, errdesc), + '__ERROR_NAME__': errname, + '__ERROR_PREFIX__': errprefix, + '__ERROR_MSG__': errdesc, + '__ERROR_MSGENC__': errdesc, + } + + formatted_error = output_format + + # If the output format starts with encode:, all of the keywords should be + # encoded. + if formatted_error.startswith('encode:'): + formatted_error = formatted_error[len('encode:'):] + encoded_keywords = replacements.keys() + else: + encoded_keywords = ['__ERROR_MSGENC__'] + + for keyword in encoded_keywords: + replacements[keyword] = _encode_error_keyword(replacements[keyword]) + + regexp = '|'.join(replacements.keys()) + return re.sub(regexp, lambda match: replacements[match.group(0)], + formatted_error) + def readfile(path): file = codecs.open(path, 'r', 'utf-8') contents = file.read() @@ -30,6 +70,28 @@ assert isidentifier('a') assert isidentifier('$0') + def testEncodeKeyword(self): + self.assertEquals(_encode_error_keyword(r'normal text'), 'normal text') + self.assertEquals(_encode_error_keyword(r'a\b'), r'a\\b') + self.assertEquals(_encode_error_keyword(r"identifier's"), r"identifier\'s") + self.assertEquals(_encode_error_keyword(r'"i"'), r'\"i\"') + self.assertEquals(_encode_error_keyword('a\tb'), r'a\tb') + self.assertEquals(_encode_error_keyword('a\rb'), r'a\rb') + self.assertEquals(_encode_error_keyword('a\nb'), r'a\nb') + + def testFormattedError(self): + self.assertEquals(format_error('__FILE__', '__LINE__', 1, 2, 'name', 'desc'), + '__LINE__') + self.assertEquals(format_error('__FILE__', r'c:\my\file', 1, 2, 'name', 'desc'), + r'c:\my\file') + self.assertEquals(format_error('encode:__FILE__', r'c:\my\file', 1, 2, 'name', 'desc'), + r'c:\\my\\file') + self.assertEquals(format_error('__ERROR_MSGENC__', r'c:\my\file', 1, 2, 'name', r'a\b'), + r'a\\b') + self.assertEquals(format_error('encode:__ERROR_MSGENC__', r'c:\my\file', 1, 2, 'name', r'a\b'), + r'a\\b') + + if __name__ == '__main__': unittest.main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |