Merge lp:~elachuni/lazr-js/jslint-html into lp:lazr-js

Proposed by Anthony Lenton
Status: Merged
Approved by: Edwin Grubbs
Approved revision: 146
Merged at revision: not available
Proposed branch: lp:~elachuni/lazr-js/jslint-html
Merge into: lp:lazr-js
Diff against target: 68 lines (+15/-9)
1 file modified
src-py/lazr/js/jslint.py (+15/-9)
To merge this branch: bzr merge lp:~elachuni/lazr-js/jslint-html
Reviewer Review Type Date Requested Status
Edwin Grubbs (community) code Approve
Review via email: mp+14837@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Anthony Lenton (elachuni) wrote :

This branch adds an option to jslint.py to allow you to lint .html files also.
I made it just lint html files always at first, but it does choke on some html files, so it's just optional in the end.

Revision history for this message
Edwin Grubbs (edwin-grubbs) wrote :

Hi Anthony,

This is great. I just have one suggestion below.

merge-conditional

-Edwin

>=== modified file 'src-py/lazr/js/jslint.py'
>--- src-py/lazr/js/jslint.py>--2009-10-21 21:43:07 +0000
>+++ src-py/lazr/js/jslint.py>--2009-11-13 17:47:54 +0000
>@@ -36,7 +39,7 @@
> # And look also at the renamed attribute for modified files.
> files_to_lint.extend(info[0] for info in delta.renamed if info[4])
>
>- # Select only the files ending in .js.
>+ # Select only the appropriate files.
> # And turn them in absolute paths.

This would be easier to read as a single sentence.
    # Select only the appropriate files and turn them in absolute paths.

review: Approve (code)
lp:~elachuni/lazr-js/jslint-html updated
147. By Anthony Lenton

Docfix from review comments.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src-py/lazr/js/jslint.py'
2--- src-py/lazr/js/jslint.py 2009-10-21 21:43:07 +0000
3+++ src-py/lazr/js/jslint.py 2009-11-13 18:12:12 +0000
4@@ -15,10 +15,13 @@
5 FULLJSLINT = os.path.join(HERE, 'fulljslint.js')
6 JSLINT_WRAPPER = os.path.join(HERE, 'jslint-wrapper.js')
7
8-
9-def js_filter(path):
10- """Filter out non-JS files."""
11- return path.endswith('.js')
12+class FiletypeFilter:
13+ include_html = False
14+ def __call__(self, path):
15+ """Return True for filetypes we want to lint."""
16+ return path.endswith('.js') or (self.include_html and
17+ path.endswith('.html'))
18+js_filter = FiletypeFilter()
19
20
21 class JSLinter:
22@@ -36,8 +39,7 @@
23 # And look also at the renamed attribute for modified files.
24 files_to_lint.extend(info[0] for info in delta.renamed if info[4])
25
26- # Select only the files ending in .js.
27- # And turn them in absolute paths.
28+ # Select only the appropriate files and turn them in absolute paths.
29 return [self.tree.abspath(f) for f in files_to_lint if js_filter(f)]
30
31 def find_files_to_lint_from_working_tree_or_parent(self):
32@@ -65,15 +67,15 @@
33
34 def find_all_files_to_lint(self):
35 """Return all the JS files that can be linted."""
36- all_js_files = []
37+ all_files = []
38 for file_id in self.tree:
39 path = self.tree.id2path(file_id)
40 # Skip build files and third party files.
41 if path.startswith('lib') or path.startswith('build'):
42 continue
43 if js_filter(path):
44- all_js_files.append(self.tree.abspath(path))
45- return all_js_files
46+ all_files.append(self.tree.abspath(path))
47+ return all_files
48
49 def jslint_rhino(self, filenames):
50 """Run the linter on all selected files using rhino."""
51@@ -134,6 +136,9 @@
52 '-e', '--engine', dest='engine', default='js', action='store',
53 help=('Javascript engine to use. Defaults to "js" (SpiderMonkey). '
54 'Use "rhino" to use the Java-based Rhino engine'))
55+ parser.add_option(
56+ '-i', '--include-html', dest='html', default=False,
57+ action='store_true', help=('Also lint .html files.'))
58
59 options, args = parser.parse_args()
60 if len(args) > 0:
61@@ -162,6 +167,7 @@
62 load_plugins()
63 options, args = get_options()
64 linter = JSLinter(options.options)
65+ js_filter.include_html = options.html
66 if args:
67 files = [f for f in args if js_filter(f)]
68 elif options.all:

Subscribers

People subscribed via source and target branches