Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 89 additions & 67 deletions its/ruling/src/test/resources/expected/python-LineLength.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'project:buildbot-0.8.6p1/buildbot/changes/mail.py':[
212,
214,
395,
460,
],
'project:buildbot-0.8.6p1/buildbot/db/migrate/versions/001_initial.py':[
Expand Down Expand Up @@ -30,8 +31,9 @@
539,
],
'project:buildbot-0.8.6p1/buildbot/test/unit/test_changes_svnpoller.py':[
80,
199,
78,
87,
206,
],
'project:buildbot-0.8.6p1/buildbot/test/unit/test_contrib_buildbot_cvs_mail.py':[
109,
Expand Down Expand Up @@ -61,6 +63,9 @@
'project:buildbot-0.8.6p1/buildbot/test/unit/test_steps_vstudio.py':[
169,
],
'project:buildbot-0.8.6p1/contrib/googlecode_atom.py':[
4,
],
'project:buildbot-0.8.6p1/contrib/trac/bbwatcher/web_ui.py':[
64,
66,
Expand All @@ -75,20 +80,24 @@
112,
119,
185,
188,
],
'project:buildbot-slave-0.8.6p1/buildslave/runprocess.py':[
193,
],
'project:buildbot-slave-0.8.6p1/buildslave/test/unit/test_bot.py':[
75,
],
'project:django-2.2.3/django/views/csrf.py':[
15,
71,
],
'project:numpy-1.16.4/numpy/core/code_generators/generate_numpy_api.py':[
12,
12,
12,
129,
131,
133,
],
'project:numpy-1.16.4/numpy/core/multiarray.py':[
1346,
1361,
],
'project:numpy-1.16.4/numpy/core/tests/test_multiarray.py':[
3833,
Expand All @@ -112,16 +121,17 @@
],
'project:numpy-1.16.4/numpy/distutils/fcompiler/absoft.py':[
23,
27,
],
'project:numpy-1.16.4/numpy/distutils/fcompiler/ibm.py':[
18,
],
'project:numpy-1.16.4/numpy/distutils/mingw32ccompiler.py':[
575,
586,
],
'project:numpy-1.16.4/numpy/doc/internals.py':[
1,
1,
9,
44,
],
'project:numpy-1.16.4/numpy/f2py/capi_maps.py':[
204,
Expand All @@ -130,24 +140,24 @@
681,
],
'project:numpy-1.16.4/numpy/f2py/cb_rules.py':[
36,
61,
195,
241,
241,
244,
246,
325,
333,
363,
388,
394,
392,
398,
],
'project:numpy-1.16.4/numpy/f2py/cfuncs.py':[
264,
330,
367,
367,
367,
367,
367,
283,
334,
368,
380,
381,
396,
397,
1008,
1011,
1014,
Expand All @@ -159,10 +169,10 @@
1033,
1037,
1041,
1044,
1044,
1044,
1044,
1045,
1089,
1120,
1123,
1158,
],
'project:numpy-1.16.4/numpy/f2py/crackfortran.py':[
Expand All @@ -185,8 +195,8 @@
221,
],
'project:numpy-1.16.4/numpy/f2py/rules.py':[
171,
270,
214,
272,
400,
401,
405,
Expand All @@ -206,23 +216,23 @@
592,
602,
760,
787,
811,
815,
806,
813,
816,
818,
881,
882,
923,
926,
960,
962,
1042,
1044,
1437,
],
'project:numpy-1.16.4/numpy/lib/tests/test_format.py':[
4,
4,
4,
4,
274,
275,
276,
277,
],
'project:numpy-1.16.4/numpy/linalg/lapack_lite/clapack_scrub.py':[
232,
Expand All @@ -231,10 +241,10 @@
115,
],
'project:tornado-2.3/demos/appengine/markdown.py':[
280,
284,
],
'project:tornado-2.3/demos/blog/markdown.py':[
280,
284,
],
'project:tornado-2.3/setup.py':[
57,
Expand All @@ -259,8 +269,8 @@
],
'project:tornado-2.3/tornado/test/web_test.py':[
8,
451,
529,
452,
530,
],
'project:twisted-12.1.0/doc/conch/examples/sshsimpleserver.py':[
45,
Expand All @@ -275,17 +285,17 @@
58,
],
'project:twisted-12.1.0/doc/historic/2003/pycon/pb/pb-slides.py':[
16,
16,
16,
16,
16,
26,
26,
26,
26,
26,
26,
17,
18,
19,
20,
21,
27,
28,
29,
30,
32,
33,
117,
118,
119,
Expand All @@ -299,6 +309,14 @@
199,
222,
],
'project:twisted-12.1.0/twisted/application/internet.py':[
1,
],
'project:twisted-12.1.0/twisted/conch/insults/insults.py':[
54,
404,
831,
],
'project:twisted-12.1.0/twisted/conch/manhole_ssh.py':[
121,
],
Expand All @@ -313,6 +331,7 @@
376,
],
'project:twisted-12.1.0/twisted/conch/ui/tkvt100.py':[
16,
34,
87,
98,
Expand All @@ -327,18 +346,18 @@
42,
],
'project:twisted-12.1.0/twisted/lore/test/test_lore.py':[
114,
140,
166,
193,
218,
272,
272,
299,
347,
442,
451,
477,
115,
141,
167,
194,
219,
276,
282,
300,
348,
445,
452,
478,
877,
],
'project:twisted-12.1.0/twisted/mail/imap4.py':[
Expand All @@ -361,6 +380,9 @@
'project:twisted-12.1.0/twisted/persisted/styles.py':[
259,
],
'project:twisted-12.1.0/twisted/protocols/ftp.py':[
126,
],
'project:twisted-12.1.0/twisted/protocols/gps/nmea.py':[
175,
],
Expand All @@ -381,8 +403,8 @@
113,
],
'project:twisted-12.1.0/twisted/test/test_sip.py':[
777,
788,
784,
797,
],
'project:twisted-12.1.0/twisted/web/client.py':[
221,
Expand Down Expand Up @@ -425,7 +447,7 @@
313,
],
'project:twisted-12.1.0/twisted/words/xish/domish.py':[
288,
357,
],
'project:twisted-12.1.0/twisted/words/xish/xpathparser.py':[
365,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
import org.sonar.python.PythonSubscriptionCheck;
import org.sonar.python.api.PythonTokenType;
import org.sonar.python.api.tree.Token;
import org.sonar.python.api.tree.Tree;

@Rule(key = LineLengthCheck.CHECK_KEY)
Expand All @@ -33,35 +31,23 @@ public class LineLengthCheck extends PythonSubscriptionCheck {
public static final String CHECK_KEY = "LineLength";
private static final int DEFAULT_MAXIMUM_LINE_LENGTH = 120;

private Token previousToken;

@RuleProperty(
key = "maximumLineLength",
defaultValue = "" + DEFAULT_MAXIMUM_LINE_LENGTH)
public int maximumLineLength = DEFAULT_MAXIMUM_LINE_LENGTH;

@Override
public void initialize(Context context) {
context.registerSyntaxNodeConsumer(Tree.Kind.FILE_INPUT, ctx -> previousToken = null);
context.registerSyntaxNodeConsumer(Tree.Kind.TOKEN, ctx -> {
Token token = (Token) ctx.syntaxNode();
if (token.type().equals(PythonTokenType.NEWLINE)) {
return;
}
if (previousToken != null && previousToken.line() != token.line()) {
String[] lines = previousToken.value().split("\r?\n|\r", -1);
int length = previousToken.column();
for (String line : lines) {
length += line.length();
if (length > maximumLineLength) {
String message = MessageFormat.format("The line contains {0,number,integer} characters which is greater than {1,number,integer} authorized.",
length, maximumLineLength);
ctx.addLineIssue(message, previousToken.line());
}
length = 0;
context.registerSyntaxNodeConsumer(Tree.Kind.FILE_INPUT, ctx -> {
String[] lines = ctx.pythonFile().content().split("\r?\n|\r", -1);
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
if (line.length() > maximumLineLength) {
String message = MessageFormat.format("The line contains {0,number,integer} characters which is greater than {1,number,integer} authorized.",
line.length(), maximumLineLength);
ctx.addLineIssue(message, i + 1);
}
}
previousToken = token;
});
}
}
3 changes: 2 additions & 1 deletion python-checks/src/test/resources/checks/lineLength.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#Noncompliant@+1
#Noncompliant@+1 {{The line contains 40 characters which is greater than 30 authorized.}}
print "This line contains 40 characters"
print
Expand All @@ -9,7 +10,7 @@

# Noncompliant@+1
something = call(('arg1', 'arg2',
# Noncompliant@+1
# Noncompliant@+1
'arg3', 'ar'),
'arg'
)
Expand Down