~launchpad-pqm/lazr-js/toolchain

« back to all changes in this revision

Viewing changes to src-py/lazr/js/jslint.py

  • Committer: Sidnei da Silva
  • Date: 2009-11-16 00:51:29 UTC
  • mto: This revision was merged to the branch mainline in revision 154.
  • Revision ID: sidnei.da.silva@canonical.com-20091116005129-8ibwjlboa38glaw5
- Improved generation of skin modules and revamped combo service to make it more twisty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
FULLJSLINT = os.path.join(HERE, 'fulljslint.js')
16
16
JSLINT_WRAPPER = os.path.join(HERE, 'jslint-wrapper.js')
17
17
 
18
 
class FiletypeFilter:
19
 
    include_html = False
20
 
    def __call__(self, path):
21
 
        """Return True for filetypes we want to lint."""
22
 
        return path.endswith('.js') or (self.include_html and
23
 
               path.endswith('.html'))
24
 
js_filter = FiletypeFilter()
 
18
 
 
19
def js_filter(path):
 
20
    """Filter out non-JS files."""
 
21
    return path.endswith('.js')
25
22
 
26
23
 
27
24
class JSLinter:
39
36
        # And look also at the renamed attribute for modified files.
40
37
        files_to_lint.extend(info[0] for info in delta.renamed if info[4])
41
38
 
42
 
        # Select only the appropriate files and turn them in absolute paths.
 
39
        # Select only the files ending in .js.
 
40
        # And turn them in absolute paths.
43
41
        return [self.tree.abspath(f) for f in files_to_lint if js_filter(f)]
44
42
 
45
43
    def find_files_to_lint_from_working_tree_or_parent(self):
67
65
 
68
66
    def find_all_files_to_lint(self):
69
67
        """Return all the JS files that can be linted."""
70
 
        all_files = []
 
68
        all_js_files = []
71
69
        for file_id in self.tree:
72
70
            path = self.tree.id2path(file_id)
73
71
            # Skip build files and third party files.
74
72
            if path.startswith('lib') or path.startswith('build'):
75
73
                continue
76
74
            if js_filter(path):
77
 
                all_files.append(self.tree.abspath(path))
78
 
        return all_files
 
75
                all_js_files.append(self.tree.abspath(path))
 
76
        return all_js_files
79
77
 
80
78
    def jslint_rhino(self, filenames):
81
79
        """Run the linter on all selected files using rhino."""
136
134
        '-e', '--engine', dest='engine', default='js', action='store',
137
135
        help=('Javascript engine to use. Defaults to "js" (SpiderMonkey). '
138
136
              'Use "rhino" to use the Java-based Rhino engine'))
139
 
    parser.add_option(
140
 
        '-i', '--include-html', dest='html', default=False,
141
 
        action='store_true', help=('Also lint .html files.'))
142
137
 
143
138
    options, args = parser.parse_args()
144
139
    if len(args) > 0:
167
162
    load_plugins()
168
163
    options, args = get_options()
169
164
    linter = JSLinter(options.options)
170
 
    js_filter.include_html = options.html
171
165
    if args:
172
166
        files = [f for f in args if js_filter(f)]
173
167
    elif options.all: