mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-29 09:52:03 +00:00
Added capp_lint check for space inside parens and dependent statement on same line, cleaned up CPString.j
This commit is contained in:
1 parent
bc09c99952
commit
b4f916351e
2 files changed
+72
-32
No files matched your search
+32
-12
@@ -66,9 +66,9 @@ CPNumericSearch = 64;
|
||||
*/
|
||||
CPDiacriticInsensitiveSearch = 128;
|
||||
|
||||
var CPStringUIDs = new CFMutableDictionary();
|
||||
var CPStringUIDs = new CFMutableDictionary(),
|
||||
|
||||
var CPStringRegexSpecialCharacters = [
|
||||
CPStringRegexSpecialCharacters = [
|
||||
'/', '.', '*', '+', '?', '|', '$', '^',
|
||||
'(', ')', '[', ']', '{', '}', '\\'
|
||||
],
|
||||
@@ -624,9 +624,9 @@ var CPStringRegexSpecialCharacters = [
|
||||
rhs = [rhs lowercaseString];
|
||||
}
|
||||
|
||||
for (; len < min; len++ )
|
||||
for (; len < min; len++)
|
||||
{
|
||||
if ( [lhs characterAtIndex:len] !== [rhs characterAtIndex:len] )
|
||||
if ([lhs characterAtIndex:len] !== [rhs characterAtIndex:len])
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -710,24 +710,31 @@ var CPStringRegexSpecialCharacters = [
|
||||
*/
|
||||
- (CPArray)pathComponents
|
||||
{
|
||||
if (length === 0) return [""];
|
||||
if (self === "/") return ["/"];
|
||||
if (length === 0)
|
||||
return [""];
|
||||
|
||||
if (self === "/")
|
||||
return ["/"];
|
||||
|
||||
var result = split('/');
|
||||
|
||||
if (result[0] === "")
|
||||
result[0] = "/";
|
||||
|
||||
var index = result.length - 1;
|
||||
|
||||
if (index > 0)
|
||||
{
|
||||
if (result[index] === "")
|
||||
result[index] = "/";
|
||||
|
||||
while (index--)
|
||||
{
|
||||
while (result[index] === "")
|
||||
{
|
||||
result.splice(index--, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -750,10 +757,12 @@ var CPStringRegexSpecialCharacters = [
|
||||
{
|
||||
var component = components[i],
|
||||
lenMinusOne = component.length - 1;
|
||||
|
||||
if (lenMinusOne >= 0 && (component !== "/" || firstRound)) // Skip "" and "/" (not first time)
|
||||
{
|
||||
if (lenMinusOne > 0 && component.indexOf("/",lenMinusOne) === lenMinusOne) // Ends with "/"
|
||||
component = component.substring(0, lenMinusOne);
|
||||
|
||||
if (firstRound)
|
||||
{
|
||||
if (component === "/")
|
||||
@@ -764,6 +773,7 @@ var CPStringRegexSpecialCharacters = [
|
||||
result += "/";
|
||||
else
|
||||
firstIsSlash = false;
|
||||
|
||||
result += component;
|
||||
}
|
||||
}
|
||||
@@ -793,6 +803,7 @@ var CPStringRegexSpecialCharacters = [
|
||||
var components = [self pathComponents],
|
||||
lastIndex = components.length - 1,
|
||||
lastComponent = components[lastIndex];
|
||||
|
||||
return lastIndex > 0 && lastComponent === "/" ? components[lastIndex - 1] : lastComponent;
|
||||
}
|
||||
|
||||
@@ -806,6 +817,7 @@ var CPStringRegexSpecialCharacters = [
|
||||
{
|
||||
var components = [self pathComponents],
|
||||
addComponents = aString && aString !== "/" ? [aString pathComponents] : [];
|
||||
|
||||
return [CPString pathWithComponents:components.concat(addComponents)];
|
||||
}
|
||||
|
||||
@@ -820,6 +832,7 @@ var CPStringRegexSpecialCharacters = [
|
||||
{
|
||||
if (ext.indexOf('/') >= 0 || length === 0 || self === "/") // Can't handle these
|
||||
return self;
|
||||
|
||||
var components = [self pathComponents],
|
||||
last = components.length - 1;
|
||||
|
||||
@@ -839,13 +852,17 @@ var CPStringRegexSpecialCharacters = [
|
||||
*/
|
||||
- (CPString)stringByDeletingLastPathComponent
|
||||
{
|
||||
if (length === 0) return "";
|
||||
if (self === "/") return "/";
|
||||
if (length === 0)
|
||||
return "";
|
||||
else if (self === "/")
|
||||
return "/";
|
||||
|
||||
var components = [self pathComponents],
|
||||
last = components.length - 1;
|
||||
|
||||
if (components[last] === "/")
|
||||
last--;
|
||||
|
||||
components.splice(last, components.length - last);
|
||||
|
||||
return [CPString pathWithComponents:components];
|
||||
@@ -860,10 +877,10 @@ var CPStringRegexSpecialCharacters = [
|
||||
- (CPString)stringByDeletingPathExtension
|
||||
{
|
||||
var extension = [self pathExtension];
|
||||
|
||||
if (extension === "")
|
||||
return self;
|
||||
|
||||
if (lastIndexOf('.') < 1)
|
||||
else if (lastIndexOf('.') < 1)
|
||||
return self;
|
||||
|
||||
return substr(0, [self length] - (extension.length + 1));
|
||||
@@ -877,6 +894,7 @@ var CPStringRegexSpecialCharacters = [
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation CPString (JSON)
|
||||
|
||||
/*!
|
||||
@@ -916,12 +934,14 @@ var CPStringRegexSpecialCharacters = [
|
||||
|
||||
@end
|
||||
|
||||
|
||||
var diacritics = [[192,198],[224,230],[231,231],[232,235],[236,239],[242,246],[249,252]], // Basic Latin ; Latin-1 Supplement.
|
||||
normalized = [65,97,99,101,105,111,117];
|
||||
|
||||
String.prototype.stripDiacritics = function()
|
||||
{
|
||||
var output = "";
|
||||
|
||||
for (var indexSource = 0; indexSource < this.length; indexSource++)
|
||||
{
|
||||
var code = this.charCodeAt(indexSource);
|
||||
|
||||
+40
-20
@@ -175,6 +175,18 @@ class LintChecker(object):
|
||||
'showPositionForGroup': 1,
|
||||
'type': ERROR_TYPE_ILLEGAL
|
||||
},
|
||||
{
|
||||
'regex': re.compile(ur'^\s*(?:(?:else )?if|for|switch|while|with)\s*\((\s+)?.+?(\s+)?\)\s*(?:(?:\{|//.*|/\*.*\*/)\s*)?$'),
|
||||
'error': 'space inside parentheses',
|
||||
'showPositionForGroup': [1, 2],
|
||||
'type': ERROR_TYPE_ILLEGAL
|
||||
},
|
||||
{
|
||||
'regex': re.compile(ur'^\s*(?:(?:else )?if|for|switch|while|with)\s*\(.+\)\s*(?:[\w_]|\[).+(;)\s*(?://.*|/\*.*\*/\s*)?$'),
|
||||
'error': 'dependent statements must be on their own line',
|
||||
'showPositionForGroup': 1,
|
||||
'type': ERROR_TYPE_ILLEGAL
|
||||
},
|
||||
{
|
||||
'regex': TRAILING_WHITESPACE_RE,
|
||||
'error': 'trailing whitespace',
|
||||
@@ -186,8 +198,8 @@ class LintChecker(object):
|
||||
'filter': {'regex': re.compile(ur'(^@import\b|^\s*' + METHOD_RE + '|^\s*[a-zA-Z_$]\w*:\s*\([a-zA-Z_$][\w<>]*\)\s*\w+|[a-zA-Z_$]\w*(\+\+|--)|([ -+*/%^&|<>!]=?|&&|\|\||<<|>>>|={1,3}|!==?)\s*[-+][\w(\[])'), 'pass': False},
|
||||
|
||||
'preprocess': STD_IGNORES,
|
||||
'regex': re.compile(ur'(?<=[\w)\]"\']|([ ]))([-+*/%^]|&&?|\|\|?|<<|>>>?)(?=[\w({\["\']|(?(1)\b\b|[ ]))'),
|
||||
'error': 'binary operator without surrounding spaces',
|
||||
'regex': re.compile(ur'(?<=[\w)\]"\']|([ ]))([-+*/%^]|&&?|\|\|?|<<|>>>?)(?=[\w({\["\']|(?(1)\b\b|[ ]))'),
|
||||
'error': 'binary operator without surrounding spaces',
|
||||
'showPositionForGroup': 2,
|
||||
'type': ERROR_TYPE_WARNING
|
||||
},
|
||||
@@ -196,8 +208,8 @@ class LintChecker(object):
|
||||
'filter': {'regex': re.compile(ur'^(@import\b|\s*' + METHOD_RE + ')'), 'pass': False},
|
||||
|
||||
'preprocess': STD_IGNORES,
|
||||
'regex': re.compile(ur'(?:[-*/%^&|<>!]=?|&&|\|\||<<|>>>|={1,3}|!==?)\s*(?<!\+)(\+)[\w(\[]'),
|
||||
'error': 'useless unary + operator',
|
||||
'regex': re.compile(ur'(?:[-*/%^&|<>!]=?|&&|\|\||<<|>>>|={1,3}|!==?)\s*(?<!\+)(\+)[\w(\[]'),
|
||||
'error': 'useless unary + operator',
|
||||
'showPositionForGroup': 1,
|
||||
'type': ERROR_TYPE_WARNING
|
||||
},
|
||||
@@ -206,8 +218,8 @@ class LintChecker(object):
|
||||
'filter': {'regex': re.compile(ur'^\s*(?:@outlet\s+)?[a-zA-Z_$]\w*\s+[a-zA-Z_$]\w*\s+@accessors\b'), 'pass': False},
|
||||
|
||||
'preprocess': STD_IGNORES,
|
||||
'regex': re.compile(ur'(?<=[\w)\]"\']|([ ]))(=|[-+*/%^&|]=|<<=|>>>?=)(?=[\w({\["\']|(?(1)\b\b|[ ]))'),
|
||||
'error': 'assignment operator without surrounding spaces',
|
||||
'regex': re.compile(ur'(?<=[\w)\]"\']|([ ]))(=|[-+*/%^&|]=|<<=|>>>?=)(?=[\w({\["\']|(?(1)\b\b|[ ]))'),
|
||||
'error': 'assignment operator without surrounding spaces',
|
||||
'showPositionForGroup': 2,
|
||||
'type': ERROR_TYPE_WARNING
|
||||
},
|
||||
@@ -216,8 +228,8 @@ class LintChecker(object):
|
||||
'filter': {'regex': re.compile(ur'^(@import\b|@implementation\b|\s*' + METHOD_RE + ')'), 'pass': False},
|
||||
|
||||
'preprocess': STD_IGNORES,
|
||||
'regex': re.compile(ur'(?<=[\w)\]"\']|([ ]))(===?|!==?|[<>]=?)(?=[\w({\["\']|(?(1)\b\b|[ ]))'),
|
||||
'error': 'comparison operator without surrounding spaces',
|
||||
'regex': re.compile(ur'(?<=[\w)\]"\']|([ ]))(===?|!==?|[<>]=?)(?=[\w({\["\']|(?(1)\b\b|[ ]))'),
|
||||
'error': 'comparison operator without surrounding spaces',
|
||||
'showPositionForGroup': 2,
|
||||
'type': ERROR_TYPE_WARNING
|
||||
},
|
||||
@@ -315,24 +327,32 @@ class LintChecker(object):
|
||||
continue
|
||||
|
||||
positions = []
|
||||
group = check.get('showPositionForGroup')
|
||||
groups = check.get('showPositionForGroup')
|
||||
|
||||
if (check.get('id') == 'tabs'):
|
||||
line = tabs2spaces(line, positions=positions)
|
||||
elif group is not None:
|
||||
elif groups is not None:
|
||||
line = tabs2spaces(line)
|
||||
|
||||
for match in regex.finditer(line):
|
||||
if group > 0:
|
||||
positions.append(match.start(group))
|
||||
else:
|
||||
# group 0 means show the first non-empty match
|
||||
for i in range(1, len(match.groups()) + 1):
|
||||
if match.start(i) >= 0:
|
||||
positions.append(match.start(i))
|
||||
break
|
||||
if not isinstance(groups, (list, tuple)):
|
||||
groups = (groups,)
|
||||
|
||||
self.error(check['error'], line=line, positions=positions, type=check['type'])
|
||||
for match in regex.finditer(line):
|
||||
for group in groups:
|
||||
if group > 0:
|
||||
start = match.start(group)
|
||||
|
||||
if start >= 0:
|
||||
positions.append(start)
|
||||
else:
|
||||
# group 0 means show the first non-empty match
|
||||
for i in range(1, len(match.groups()) + 1):
|
||||
if match.start(i) >= 0:
|
||||
positions.append(match.start(i))
|
||||
break
|
||||
|
||||
if positions:
|
||||
self.error(check['error'], line=line, positions=positions, type=check['type'])
|
||||
|
||||
def next_statement(self, expect_line=False, check_line=True):
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user