Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
[lint] Add the ability to disable the linter via a flag in the config…
Browse files Browse the repository at this point in the history
… file.
  • Loading branch information
jverkoey committed Mar 1, 2011
1 parent 8464e20 commit fc18dc8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Products
*.xcworkspace *.xcworkspace
xcuserdata xcuserdata
.DS_Store .DS_Store
config
src/Three20/*.h src/Three20/*.h
src/Three20Core/*.h src/Three20Core/*.h
src/Three20Network/*.h src/Three20Network/*.h
Expand Down
17 changes: 17 additions & 0 deletions config.template
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,17 @@
;
; This Three20 config file is used by various scripts in the Three20 ecosystem to
; change configuration settings.
;
; NOTICE: This is just a template. Changes to this file will not be noticed by scripts.
; To configure Three20, copy this file and rename it to "config" in the same folder.
;
; This file represents the assumed "defaults" when the config file does not exist.
;

; The Three20 lint tool validates source code for the Three20 style guidelines to ensure a
; consistent style across the code base.
[lint]

; By default, Three20 will run the linter on all Three20 projects. If you are hacking on
; Three20 and don't really care about stylistic consistency, set this to false.
enabled_for_projects = true
24 changes: 19 additions & 5 deletions src/scripts/lint
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# encoding: utf-8 # encoding: utf-8
""" """
lint.py lint
Validate style guidelines for a given source file. Validate style guidelines for a given source file.
Expand Down Expand Up @@ -29,6 +29,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
""" """


import ConfigParser
import logging import logging
import os import os
import Paths import Paths
Expand Down Expand Up @@ -61,9 +62,20 @@ Verify Three20 style guidelines for source code.'''
if len(args) == 0: if len(args) == 0:
parser.print_help() parser.print_help()


enabled_for_projects = True

# Allow third-party developers to disable the linter entirely. See config.template for
# more information in the "lint" section.
configpath = os.path.join(os.path.dirname(Paths.src_dir), 'config')
if os.path.exists(configpath):
config = ConfigParser.ConfigParser()
config.read(configpath)
enabled_for_projects = config.getboolean('lint', 'enabled_for_projects')

# If we're running the linter from Xcode, let's just process the project. # If we're running the linter from Xcode, let's just process the project.
if 'PROJECT_FILE_PATH' in os.environ: if 'PROJECT_FILE_PATH' in os.environ:
lint_project(os.environ['PROJECT_FILE_PATH'], options) if enabled_for_projects:
lint_project(os.environ['PROJECT_FILE_PATH'], options)
else: else:
for filename in args: for filename in args:
lint(filename, options) lint(filename, options)
Expand Down Expand Up @@ -146,8 +158,10 @@ def lint_project(project_path, options):
if lint(filename, options): if lint(filename, options):
# Only update the last known modification time if there weren't any errors. # Only update the last known modification time if there weren't any errors.
mtimes[filename] = mtime mtimes[filename] = mtime
elif filename in mtimes: else:
del mtimes[filename] print "If you would like to disable the lint tool, please read the instructions in config.template in the root of the Three20 project"
if filename in mtimes:
del mtimes[filename]


# Write out the lint data once we're done with this project. Thanks, pickle! # Write out the lint data once we're done with this project. Thanks, pickle!
if tempdir: if tempdir:
Expand All @@ -167,7 +181,7 @@ def lint(filename, options):
if 'PROJECT_FILE_PATH' in os.environ: if 'PROJECT_FILE_PATH' in os.environ:
formatter = logging.Formatter(filename+":%(linenumber)s: warning: "+relpath(os.getcwd(), filename)+":%(linenumber)s: %(message)s") formatter = logging.Formatter(filename+":%(linenumber)s: warning: "+relpath(os.getcwd(), filename)+":%(linenumber)s: %(message)s")
else: else:
formatter = logging.Formatter("warning: "+filename+":%(linenumber)s: %(message)s") formatter = logging.Formatter(filename+":%(linenumber)s: %(message)s")
ch.setFormatter(formatter) ch.setFormatter(formatter)
logger.addHandler(ch) logger.addHandler(ch)


Expand Down

0 comments on commit fc18dc8

Please sign in to comment.