[javascriptlint-commit] SF.net SVN: javascriptlint:[308] trunk
Status: Beta
Brought to you by:
matthiasmiller
|
From: <mat...@us...> - 2013-09-28 04:08:33
|
Revision: 308
http://sourceforge.net/p/javascriptlint/code/308
Author: matthiasmiller
Date: 2013-09-28 04:08:31 +0000 (Sat, 28 Sep 2013)
Log Message:
-----------
#42 Failure when input file is not utf-8 encoded
Allow passing the input file encoding on the command line.
Modified Paths:
--------------
trunk/javascriptlint/conf.py
trunk/javascriptlint/fs.py
trunk/javascriptlint/jsl.py
trunk/javascriptlint/lint.py
trunk/test.py
Modified: trunk/javascriptlint/conf.py
===================================================================
--- trunk/javascriptlint/conf.py 2013-09-28 03:50:06 UTC (rev 307)
+++ trunk/javascriptlint/conf.py 2013-09-28 04:08:31 UTC (rev 308)
@@ -187,7 +187,7 @@
def loadfile(self, path):
path = os.path.abspath(path)
- conf = fs.readfile(path)
+ conf = fs.readfile(path, 'utf-8')
try:
self.loadtext(conf, dir=os.path.dirname(path))
except ConfError, error:
Modified: trunk/javascriptlint/fs.py
===================================================================
--- trunk/javascriptlint/fs.py 2013-09-28 03:50:06 UTC (rev 307)
+++ trunk/javascriptlint/fs.py 2013-09-28 04:08:31 UTC (rev 308)
@@ -2,8 +2,8 @@
import codecs
import os
-def readfile(path):
- file = codecs.open(path, 'r', 'utf-8')
+def readfile(path, encoding):
+ file = codecs.open(path, 'r', encoding)
contents = file.read()
if contents and contents[0] == unicode(codecs.BOM_UTF8, 'utf8'):
contents = contents[1:]
Modified: trunk/javascriptlint/jsl.py
===================================================================
--- trunk/javascriptlint/jsl.py 2013-09-28 03:50:06 UTC (rev 307)
+++ trunk/javascriptlint/jsl.py 2013-09-28 04:08:31 UTC (rev 308)
@@ -20,17 +20,17 @@
'errors': 0
}
-def _dump(paths):
+def _dump(paths, encoding):
for path in paths:
- script = fs.readfile(path)
+ script = fs.readfile(path, encoding)
jsparse.dump_tree(script)
-def _lint(paths, conf_, printpaths):
+def _lint(paths, conf_, printpaths, encoding):
def lint_error(path, line, col, errname, errdesc):
_lint_results['warnings'] = _lint_results['warnings'] + 1
print util.format_error(conf_['output-format'], path, line, col,
errname, errdesc)
- lint.lint_files(paths, lint_error, conf=conf_, printpaths=printpaths)
+ lint.lint_files(paths, lint_error, encoding, conf=conf_, printpaths=printpaths)
def _resolve_paths(path, recurse):
# Build a list of directories
@@ -97,6 +97,8 @@
help="suppress lint summary")
add("--help:conf", dest="showdefaultconf", action="store_true", default=False,
help="display the default configuration file")
+ add("--encoding", dest="encoding", metavar="ENCODING", default="utf-8",
+ help="encoding for input file(s)")
parser.set_defaults(verbosity=1)
options, args = parser.parse_args()
@@ -138,9 +140,9 @@
else:
paths.append(arg)
if options.dump:
- profile_func(_dump, paths)
+ profile_func(_dump, paths, options.encoding)
else:
- profile_func(_lint, paths, conf_, options.printlisting)
+ profile_func(_lint, paths, conf_, options.printlisting, options.encoding)
if options.printsummary:
print '\n%i error(s), %i warnings(s)' % (_lint_results['errors'],
Modified: trunk/javascriptlint/lint.py
===================================================================
--- trunk/javascriptlint/lint.py 2013-09-28 03:50:06 UTC (rev 307)
+++ trunk/javascriptlint/lint.py 2013-09-28 04:08:31 UTC (rev 308)
@@ -286,14 +286,14 @@
else:
assert False, 'Invalid internal tag type %s' % tag['type']
-def lint_files(paths, lint_error, conf=conf.Conf(), printpaths=True):
- def lint_file(path, kind, jsversion):
+def lint_files(paths, lint_error, encoding, conf=conf.Conf(), printpaths=True):
+ def lint_file(path, kind, jsversion, encoding):
def import_script(import_path, jsversion):
# The user can specify paths using backslashes (such as when
# linting Windows scripts on a posix environment.
import_path = import_path.replace('\\', os.sep)
import_path = os.path.join(os.path.dirname(path), import_path)
- return lint_file(import_path, 'js', jsversion)
+ return lint_file(import_path, 'js', jsversion, encoding)
def _lint_error(*args):
return lint_error(normpath, *args)
@@ -302,7 +302,7 @@
return lint_cache[normpath]
if printpaths:
print normpath
- contents = fs.readfile(path)
+ contents = fs.readfile(path, encoding)
lint_cache[normpath] = _Script()
script_parts = []
@@ -334,9 +334,9 @@
for path in paths:
ext = os.path.splitext(path)[1]
if ext.lower() in ['.htm', '.html']:
- lint_file(path, 'html', None)
+ lint_file(path, 'html', None, encoding)
else:
- lint_file(path, 'js', None)
+ lint_file(path, 'js', None, encoding)
def _lint_script_part(scriptpos, jsversion, script, script_cache, conf,
ignores, report_native, report_lint, import_callback):
Modified: trunk/test.py
===================================================================
--- trunk/test.py 2013-09-28 03:50:06 UTC (rev 307)
+++ trunk/test.py 2013-09-28 04:08:31 UTC (rev 308)
@@ -61,7 +61,7 @@
else:
unexpected_warnings.append(warning + (errdesc,))
- javascriptlint.lint.lint_files([path], lint_error, conf=conf)
+ javascriptlint.lint.lint_files([path], lint_error, 'utf-8', conf=conf)
errors = []
if expected_warnings:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|