Skip to content

Commit

Permalink
- Added CSS checking via cssutils
Browse files Browse the repository at this point in the history
- Added some more test files
  • Loading branch information
Adam Groszer committed Apr 4, 2012
1 parent aeb9d87 commit 880bd68
Show file tree
Hide file tree
Showing 8 changed files with 720 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGES.txt
Expand Up @@ -4,7 +4,9 @@ CHANGES
0.5.1 (unreleased)
------------------

- Nothing changed yet.
- Added CSS checking via cssutils

- Added some more test files


0.5.0 (2012-04-02)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -28,6 +28,7 @@ def read(*rnames):
'setuptools',
'pyflakes == 0.4.0', # pyflakes 0.5.0 does not like python 2.6's AST
'polib',
'cssutils',
],
extras_require=dict(
test=[]),
Expand Down
18 changes: 17 additions & 1 deletion src/refline/srccheck/README.txt
Expand Up @@ -3,7 +3,7 @@ Source checking/linting tool

It's easy to use.

Import the package yuou want to check:
Import the package you want to check:

>>> import refline.srccheck

Expand All @@ -17,6 +17,10 @@ It will pinpoint the problems found.
>>> c = checker(refline.srccheck)
>>> c.run()
<BLANKLINE>
testing/bad.css
---------------
PropertyValue: No match: ('CHAR', u':', 4, 10)
<BLANKLINE>
testing/bad.py
--------------
Tab found in file
Expand All @@ -25,6 +29,18 @@ It will pinpoint the problems found.
--------------
undefined name 'bar'
6: foo = bar
<BLANKLINE>
testing/some.js
---------------
Breakpoint found in line
2: console.log("blabla");
<BLANKLINE>
testing/z3c.form.po
-------------------
Fuzzy/untranslated found
1: 1 untranslated items
Fuzzy/untranslated found
1: 1 fuzzy items


Just in case you cannot / do not want to avoid those problems,
Expand Down
41 changes: 41 additions & 0 deletions src/refline/srccheck/checker.py
Expand Up @@ -14,12 +14,14 @@
"""Sourcecode checker, to be used in unittests
"""

import logging
import os
import os.path
import string
import polib
import fnmatch

from cssutils import parse
from refline.srccheck import pyflakes

INDENT = ' '
Expand Down Expand Up @@ -226,6 +228,41 @@ def check(self, filename, content, lines):
self.log(0, '')


class CSSLogger(object):
# this is a fake logger that redirects the actual logging calls to us

def __init__(self, checker):
self.checker = checker

def noop(self, *args, **kw):
pass

debug = noop
info = noop
setLevel = noop
getEffectiveLevel = noop
addHandler = noop
removeHandler = noop

def error(self, msg):
self.checker.error = msg
# can't add much help, all info is encoded in msg
self.checker.log(0)

warn = error
critical = error
fatal = error


class CSSChecker(BaseChecker):
error = 'CSS'

def check(self, filename, content, lines):
parse.CSSParser(log=CSSLogger(self),
loglevel=logging.WARN,
validate=True).parseString(content)


PY_CHECKS = [
TabChecker(),
NonAsciiChecker(),
Expand Down Expand Up @@ -258,6 +295,9 @@ def check(self, filename, content, lines):
]
ZCML_CHECKS = [
]
CSS_CHECKS = [
CSSChecker(),
]

CHECKS = {
'py': PY_CHECKS,
Expand All @@ -268,6 +308,7 @@ def check(self, filename, content, lines):
'po': PO_CHECKS,
'jpg': JPG_CHECKS,
'zcml': ZCML_CHECKS,
'css': CSS_CHECKS,
}


Expand Down
6 changes: 6 additions & 0 deletions src/refline/srccheck/testing/bad.css
@@ -0,0 +1,6 @@

div.class {
height: 10px
width: 20
}

12 changes: 12 additions & 0 deletions src/refline/srccheck/testing/ignored_bad.py
@@ -0,0 +1,12 @@
# this is a file full with problems
# but ignored with:
# checker_ignore_this_file

import os

def doit():
foo = bar

def with_tab():
print "there's a tab"

7 changes: 7 additions & 0 deletions src/refline/srccheck/testing/some.js
@@ -0,0 +1,7 @@
var zz = function(a,c) {
console.log("blabla");
}

var yy = function(a,c) {
//console.log("not found");
}

0 comments on commit 880bd68

Please sign in to comment.