1#!/usr/bin/env python
2# python2.6 for command-line runs using p4lib.  pylint: disable-msg=C6301
3#
4# Copyright 2007 The Closure Linter Authors. All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#      http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS-IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18"""Automatically fix simple style guide violations."""
19
20__author__ = 'robbyw@google.com (Robert Walker)'
21
22import sys
23
24import gflags as flags
25from closure_linter import checker
26from closure_linter import error_fixer
27from closure_linter.common import simplefileflags as fileflags
28
29FLAGS = flags.FLAGS
30flags.DEFINE_list('additional_extensions', None, 'List of additional file '
31                  'extensions (not js) that should be treated as '
32                  'JavaScript files.')
33
34
35def main(argv = None):
36  """Main function.
37
38  Args:
39    argv: Sequence of command line arguments.
40  """
41  if argv is None:
42    argv = flags.FLAGS(sys.argv)
43
44  suffixes = ['.js']
45  if FLAGS.additional_extensions:
46    suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions]
47
48  files = fileflags.GetFileList(argv, 'JavaScript', suffixes)
49
50  style_checker = checker.JavaScriptStyleChecker(error_fixer.ErrorFixer())
51
52  # Check the list of files.
53  for filename in files:
54    style_checker.Check(filename)
55
56if __name__ == '__main__':
57  main()
58