Skip to content

Commit 06dac6c

Browse files
Kannan Goundanbraincore
authored andcommitted
Make "arc lint" use Flake8. Fix lint errors.
Reviewed By: kelkabany
1 parent d6383d2 commit 06dac6c

17 files changed

Lines changed: 113 additions & 58 deletions

File tree

.arc_lib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.phutil_module_cache
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
phutil_register_library('babel-arcanist-utils', __FILE__);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/**
4+
* This file is automatically generated. Use 'arc liberate' to rebuild it.
5+
*
6+
* @generated
7+
* @phutil-library-version 2
8+
*/
9+
phutil_register_library_map(array(
10+
'__library_version__' => 2,
11+
'class' => array(
12+
'BabelLintEngine' => 'lint/BabelLintEngine.php',
13+
),
14+
'function' => array(),
15+
'xmap' => array(
16+
'BabelLinter' => 'ArcanistLintEngine',
17+
),
18+
));

.arc_lib/lint/BabelLintEngine.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
final class BabelLintEngine extends ArcanistLintEngine {
4+
5+
public function buildLinters() {
6+
$flake8 = new ArcanistFlake8Linter();
7+
8+
$pythonPaths = array();
9+
foreach ($this->getPaths() as $path) {
10+
if (!self::endsWith($path, ".py")) continue; // Only include Python files.
11+
if (self::startsWith($path, "example/api/")) continue; // Old crufty stuff.
12+
\array_push($pythonPaths, $path);
13+
}
14+
$flake8->setPaths($pythonPaths);
15+
16+
return array(
17+
"flake8" => $flake8,
18+
);
19+
}
20+
21+
public static function startsWith($haystack, $needle) {
22+
return \substr($haystack, 0, strlen($needle)) === $needle;
23+
}
24+
25+
public static function endsWith($haystack, $needle) {
26+
return \substr($haystack, \strlen($haystack) - \strlen($needle)) === $needle;
27+
}
28+
}

.arcconfig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33
"conduit_uri" : "https://tails.corp.dropbox.com/api/",
44
"copyright_holder" : "Dropbox",
55
"repository.callsign": "BABEL",
6-
"immutable_history": false
6+
"immutable_history": false,
7+
8+
"lint_engine": "BabelLintEngine",
9+
10+
"phutil_libraries": {
11+
"babel-arcanist-utils": ".arc_lib"
12+
}
713
}

babelapi/babel/lexer.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ def token(self):
5555
else:
5656
if r is None and self.cur_indent > 0:
5757
if self.last_token and self.last_token.type not in ('NEWLINE', 'LINE'):
58-
newline_token = self._create_token('NEWLINE', '\n', self.lex.lineno, self.lex.lexpos)
58+
newline_token = self._create_token('NEWLINE', '\n', self.lex.lineno,
59+
self.lex.lexpos)
5960
self.tokens_queue.append(newline_token)
6061
dedent_count = self.cur_indent / 4
61-
dedent_token = self._create_token('DEDENT', '\t', self.lex.lineno, self.lex.lexpos)
62+
dedent_token = self._create_token('DEDENT', '\t', self.lex.lineno,
63+
self.lex.lexpos)
6264
self.tokens_queue.extend([dedent_token] * dedent_count)
6365

6466
self.cur_indent = 0
@@ -90,11 +92,11 @@ def test(self, data):
9092

9193
# List of token names
9294
tokens = (
93-
'ID',
94-
'KEYWORD',
95-
'PATH',
96-
'PIPE',
97-
'DOT',
95+
'ID',
96+
'KEYWORD',
97+
'PATH',
98+
'PIPE',
99+
'DOT',
98100
)
99101

100102
# Whitespace tokens
@@ -128,8 +130,8 @@ def test(self, data):
128130

129131
# Regular expression rules for simple tokens
130132
t_DOT = r'\.'
131-
t_LPAR = r'\('
132-
t_RPAR = r'\)'
133+
t_LPAR = r'\('
134+
t_RPAR = r'\)'
133135
t_EQ = r'='
134136
t_COMMA = r','
135137
t_PIPE = r'\|'

babelapi/babel/parser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,10 @@ def p_coverage(self, p):
385385
p[0] = p[2]
386386

387387
def p_struct(self, p):
388-
'struct : STRUCT ID inheritance coverage NEWLINE INDENT docsection field_list example_list DEDENT'
388+
"""
389+
struct : STRUCT ID inheritance coverage NEWLINE \
390+
INDENT docsection field_list example_list DEDENT
391+
"""
389392
p[0] = BabelTypeDef(p.lineno(1), p.lexpos(1), p[1], p[2], extends=p[3], coverage=p[4])
390393
if p[7]:
391394
p[0].set_doc(p[7])

babelapi/compiler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import inspect
55
import os
66
import re
7-
import sys
87
import shutil
98

109
from babelapi.generator import Generator

babelapi/data_type.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ def get_example(self, label):
642642
raise Exception('No example with label %r for subtype '
643643
'%r' % (label, field.data_type.name))
644644
elif (isinstance(field.data_type, List) and
645-
isinstance(field.data_type.data_type, CompositeType)):
645+
isinstance(field.data_type.data_type, CompositeType)):
646646
example_copy[field.name] = [field.data_type.data_type.get_example(label)]
647647
return example_copy
648648

@@ -704,9 +704,8 @@ def has_example(self, label):
704704
def get_example(self, label):
705705
for field in self.fields:
706706
if (isinstance(field, Field)
707-
and isinstance(field.data_type, CompositeType)
708-
and field.data_type.has_example(label)):
709-
707+
and isinstance(field.data_type, CompositeType)
708+
and field.data_type.has_example(label)):
710709
return {field.name: field.data_type.get_example(label)}
711710
else:
712711
# Fallback to checking for direct symbols

babelapi/lang/ruby.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def format_type(self, data_type):
4040
return RubyTargetLanguage._type_table.get(data_type.__class__, data_type.name)
4141

4242
def format_obj(self, o):
43-
assert not isinstance(o, dict), "Bad argument to format_obj: pprint's dict formatting is not valid Ruby."
43+
assert not isinstance(o, dict), \
44+
"Bad argument to format_obj: pprint's dict formatting is not valid Ruby."
4445
if o is True:
4546
return 'true'
4647
if o is False:

0 commit comments

Comments
 (0)