mulang 5.3.0 → 6.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/console +2 -2
- data/bin/mulang +0 -0
- data/lib/locales/en.yml +37 -57
- data/lib/locales/es.yml +36 -56
- data/lib/locales/operators.yml +96 -0
- data/lib/locales/pt.yml +34 -54
- data/lib/mulang.rb +53 -4
- data/lib/mulang/code.rb +40 -10
- data/lib/mulang/expectation.rb +54 -24
- data/lib/mulang/expectation/i18n.rb +11 -45
- data/lib/mulang/language.rb +86 -14
- data/lib/mulang/sexp.rb +80 -0
- data/lib/mulang/tokens.rb +276 -0
- data/lib/mulang/version.rb +2 -2
- metadata +22 -6
data/lib/locales/pt.yml
CHANGED
@@ -5,17 +5,17 @@ pt:
|
|
5
5
|
must_not: 'não deve'
|
6
6
|
must: 'deve'
|
7
7
|
solution: 'a solução'
|
8
|
-
with_char: ' com o caractere <
|
9
|
-
with_false: ' com o valor <
|
8
|
+
with_char: ' com o caractere <code>%{value}</code>'
|
9
|
+
with_false: ' com o valor <code>%{keyword_False}</code>'
|
10
10
|
with_literal: ' com um valor literal'
|
11
11
|
with_logic: ' com uma expressão booleana'
|
12
12
|
with_math: ' com uma expressão matemática'
|
13
|
-
with_nil: ' com <
|
13
|
+
with_nil: ' com <code>%{keyword_Nil}</code>'
|
14
14
|
with_nonliteral: ' com uma expressão não literal'
|
15
|
-
with_number: ' com o número <
|
16
|
-
with_string: ' com a string <
|
17
|
-
with_symbol: ' com o símbolo <
|
18
|
-
with_true: ' com o valor <
|
15
|
+
with_number: ' com o número <code>%{value}</code>'
|
16
|
+
with_string: ' com a string <code>%{value}</code>'
|
17
|
+
with_symbol: ' com o símbolo <code>%{value}</code>'
|
18
|
+
with_true: ' com o valor <code>%{keyword_True}</code>'
|
19
19
|
inspection:
|
20
20
|
Assigns_except: '%{binding} %{must} atribuir algo diferente a %{target}%{matching}'
|
21
21
|
Assigns_like: '%{binding} %{must} atribuir algo semelhante ao %{target}%{matching}'
|
@@ -47,7 +47,7 @@ pt:
|
|
47
47
|
DeclaresComputationWithArity3_named: '%{target} %{must} tem três parâmetros'
|
48
48
|
DeclaresComputationWithArity4_named: '%{target} %{must} tem quatro parâmetros'
|
49
49
|
DeclaresComputationWithArity5_named: '%{target} %{must} tem cinco parâmetros'
|
50
|
-
DeclaresEntryPoint: '%{binding} %{must} declarar um <
|
50
|
+
DeclaresEntryPoint: '%{binding} %{must} declarar um <code>%{keyword_EntryPoint}</code>%{matching}'
|
51
51
|
DeclaresEnumeration_except: '%{binding} %{must} declarar enumerações que não são chamadas %{target}'
|
52
52
|
DeclaresEnumeration_like: '%{binding} %{must} declarar uma enumeração de nome semelhante a %{target}'
|
53
53
|
DeclaresEnumeration_named: '%{binding} %{must} declarar uma enumeração %{target}'
|
@@ -104,26 +104,27 @@ pt:
|
|
104
104
|
Delegates: '%{binding} %{must} delegar'
|
105
105
|
DiscardsExceptions: '%{binding} está silenciosamente ignorando exceções'
|
106
106
|
DoesConsolePrint: '%{binding} está fazendo impressões na tela'
|
107
|
-
DoesNilTest: '%{binding} faz comparações contra <
|
108
|
-
DoesNullTest: '%{binding} faz comparações contra <
|
107
|
+
DoesNilTest: '%{binding} faz comparações contra <code>%{keyword_Nil}</code>'
|
108
|
+
DoesNullTest: '%{binding} faz comparações contra <code>%{keyword_Nil}</code>'
|
109
109
|
DoesTypeTest: '%{binding} faz comparações contra strings'
|
110
|
-
HasAssignmentCondition: '%{binding} avalia o resultado de uma atribuição no qual uma expressão booleana era esperada. Talvez você queira usar o operador <
|
111
|
-
HasAssignmentReturn: '%{binding} retorna o resultado de uma atribuição. Talvez você queira usar o operador <
|
110
|
+
HasAssignmentCondition: '%{binding} avalia o resultado de uma atribuição no qual uma expressão booleana era esperada. Talvez você queira usar o operador <code>%{operator_Equal}</code>?'
|
111
|
+
HasAssignmentReturn: '%{binding} retorna o resultado de uma atribuição. Talvez você queira usar o operador <code>%{operator_Equal}</code>?'
|
112
112
|
HasCodeDuplication: '%{binding} tem código repetido'
|
113
113
|
HasDeclarationTypos_named: 'A solução deve declarar %{target}, mas declara %{binding}. Você poderia ter cometido um erro de digitação?'
|
114
114
|
HasEmptyIfBranches: '%{binding} tem uma ramificaçao %{keyword_If} vazia'
|
115
|
-
HasEmptyRepeat: '%{binding} tem um <
|
115
|
+
HasEmptyRepeat: '%{binding} tem um <code>%{keyword_Repeat}</code> vazio'
|
116
|
+
HasEqualIfBranches: '%{binding} possui <code>%{keyword_If}</code>s desnecessários porque seus dois ramos são iguais'
|
116
117
|
HasLongParameterList: '%{binding} tem muitos parâmetros. Você pode estar perdendo uma abstração.'
|
117
118
|
HasMisspelledBindings: '%{binding} está incorreto. Verifique a ortografia e tente não usar abreviaturas'
|
118
119
|
HasMisspelledIdentifiers: '%{binding} está incorreto. Verifique a ortografia e tente não usar abreviaturas'
|
119
120
|
HasRedundantBooleanComparison: '%{binding} faz comparações booleanas desnecessárias'
|
120
121
|
HasRedundantGuards: '%{binding} possui protetores desnecessários'
|
121
|
-
HasRedundantIf: '%{binding} <
|
122
|
+
HasRedundantIf: '%{binding} possui <code>%{keyword_If}</code>s desnecessários que podem ser substituídos por expressões booleanas'
|
122
123
|
HasRedundantLambda: '%{binding} possui lambdas desnecessários'
|
123
124
|
HasRedundantLocalVariableReturn: '%{binding} usa variáveis locais desnecessárias; você pode retornar a expressão diretamente'
|
124
125
|
HasRedundantParameter: '%{binding} possui parâmetros desnecessários (pode ser removido por ponto-livre)'
|
125
|
-
HasRedundantReduction: '%{binding} usa <
|
126
|
-
HasRedundantRepeat: '%{binding} tem <
|
126
|
+
HasRedundantReduction: '%{binding} usa <code>%{keyword_Is}</code>, mas não executa cálculos'
|
127
|
+
HasRedundantRepeat: '%{binding} tem <code>%{keyword_Repeat}</code> desnecessário'
|
127
128
|
HasTooManyMethods: '%{binding} tem muitos métodos'
|
128
129
|
HasTooShortBindings: '%{binding} é um identificador muito curto'
|
129
130
|
HasTooShortIdentifiers: '%{binding} é um identificador muito curto'
|
@@ -144,7 +145,8 @@ pt:
|
|
144
145
|
Instantiates_named: '%{binding} %{must} instantiate %{target}'
|
145
146
|
Instantiates: '%{binding} %{must} instanciar objetos'
|
146
147
|
IsLongCode: '%{binding} é muito longo. Tente delegar mais'
|
147
|
-
|
148
|
+
JavaScript#UsesVarInsteadOfLet: '% {binding} deve usar <code>let</code> em vez de <code>var</code>'
|
149
|
+
OverridesEqualOrHashButNotBoth: '%{binding} redefine os métodos <code>equals</code> ou <code>hash </code>, mas não ambos'
|
148
150
|
Raises_except: '%{binding} %{must} lançar exceções diferentes de %{target}'
|
149
151
|
Raises_like: '%{binding} %{must} lançar exceções semelhantes a %{target}'
|
150
152
|
Raises_named: '%{binding} %{must} launch %{target}'
|
@@ -156,9 +158,10 @@ pt:
|
|
156
158
|
Returns: '%{binding} %{must} retornar%{matching}'
|
157
159
|
ReturnsNil: '%{binding} retorna nulo, o que é uma prática ruim'
|
158
160
|
ReturnsNull: '%{binding} retorna nulo, o que é uma prática ruim'
|
159
|
-
ShouldInvertIfCondition: '%{binding} deve inverter a condição da <
|
161
|
+
ShouldInvertIfCondition: '%{binding} deve inverter a condição da <code>%{keyword_If}</code> e trocar as ramos'
|
162
|
+
ShouldUseStrictComparators: '%{binding} deve usar os operadores de equivalência <code>%{operator_Equal}</code> e <code>%{operator_NotEqual}</code> em vez dos operadores de similaridade <code>%{operator_Similar}</code> e <code>%{operator_NotSimilar}</code> '
|
160
163
|
SubordinatesDeclarationsTo: 'Todas as declarações em %{binding} %{must} ser usadas a partir de %{target}'
|
161
|
-
SubordinatesDeclarationsToEntryPoint: 'Todas as declarações em %{binding} %{must} devem ser usadas a partir de <
|
164
|
+
SubordinatesDeclarationsToEntryPoint: 'Todas as declarações em %{binding} %{must} devem ser usadas a partir de <code>%{keyword_EntryPoint}</code>'
|
162
165
|
TypesAs_named: '%{binding} %{must} é do tipo %{target}'
|
163
166
|
TypesAs: '%{binding} %{must} tem tipo'
|
164
167
|
TypesReturnAs_named: '%{binding} %{must} tem tipo de valor de retorno %{target}'
|
@@ -167,59 +170,36 @@ pt:
|
|
167
170
|
Uses_like: '%{binding} %{must} delegar algo semelhante ao %{target}'
|
168
171
|
Uses_named: '%{binding} %{must} usar %{target}'
|
169
172
|
Uses: '%{binding} %{must} delegar'
|
170
|
-
UsesAnd: '%{binding} %{must} utilizar <i>%{operator_And}</i>'
|
171
173
|
UsesAnonymousVariable: '%{binding} %{must} usar uma variável anônima'
|
172
|
-
UsesBackwardComposition: '%{binding} %{must} utilizar <i>%{operator_BackwardComposition}</i>'
|
173
|
-
UsesBitwiseAnd: '%{binding} %{must} utilizar <i>%{operator_BitwiseAnd}</i>'
|
174
|
-
UsesBitwiseLeftShift: '%{binding} %{must} utilizar <i>%{operator_BitwiseLeftShift}</i>'
|
175
|
-
UsesBitwiseOr: '%{binding} %{must} utilizar <i>%{operator_BitwiseOr}</i>'
|
176
|
-
UsesBitwiseRightShift: '%{binding} %{must} utilizar <i>%{operator_BitwiseRightShift}</i>'
|
177
|
-
UsesBitwiseXor: '%{binding} %{must} utilizar <i>%{operator_BitwiseXor}</i>'
|
178
174
|
UsesComposition: '%{binding} %{must} usar a composição'
|
179
175
|
UsesComprehension: '%{binding} %{must} usar listas pelo entendimento'
|
180
176
|
UsesConditional: '%{binding} %{must} usar conditional'
|
181
177
|
UsesCut: '%{binding} usa o operador !, que é uma má prática'
|
182
|
-
|
183
|
-
UsesDyamicPolymorphism: '%{binding} %{must} usar polimorfismo'
|
178
|
+
UsesDynamicPolymorphism: '%{binding} %{must} usar polimorfismo'
|
184
179
|
UsesDynamicMethodOverload: '%{binding} %{must} usar sobrecarga'
|
185
|
-
UsesEqual: '%{binding} %{must} utilizar <i>%{operator_Equal}</i>'
|
186
180
|
UsesExceptionHandling: '%{binding} %{must} executar o tratamento de exceção'
|
187
181
|
UsesExceptions: '%{binding} %{must} usar exceções'
|
188
|
-
UsesFail: '%{binding} usa <
|
189
|
-
UsesFindall: '%{binding} %{must} usar <
|
190
|
-
UsesFor: '%{binding} %{must} usar <
|
191
|
-
UsesForall: '%{binding} %{must} usar <
|
192
|
-
UsesForeach: '%{binding} %{must} usar <
|
193
|
-
UsesForwardComposition: '%{binding} %{must} utilizar <i>%{operator_ForwardComposition}</i>'
|
194
|
-
UsesGreatherOrEqualThan: '%{binding} %{must} utilizar <i>%{operator_GreatherOrEqualThan}</i>'
|
195
|
-
UsesGreatherThan: '%{binding} %{must} utilizar <i>%{operator_GreatherThan}</i>'
|
182
|
+
UsesFail: '%{binding} usa <code>%{keyword_Fail}</li>, o que é uma prática ruim'
|
183
|
+
UsesFindall: '%{binding} %{must} usar <code>%{keyword_Findall}</code>'
|
184
|
+
UsesFor: '%{binding} %{must} usar <code>%{keyword_For}</code>%{matching}'
|
185
|
+
UsesForall: '%{binding} %{must} usar <code>%{keyword_Forall}</code>'
|
186
|
+
UsesForeach: '%{binding} %{must} usar <code>%{keyword_ForEach}</code>%{matching}'
|
196
187
|
UsesGuards: '%{binding} %{must} usar guardas%{matching}'
|
197
|
-
|
198
|
-
UsesIf: '%{binding} %{must} usar <i>%{keyword_If}</i>%{matching}'
|
188
|
+
UsesIf: '%{binding} %{must} usar <code>%{keyword_If}</code>%{matching}'
|
199
189
|
UsesInheritance: '%{binding} %{must} usar herança'
|
200
190
|
UsesLambda: '%{binding} %{must} usar expressões lambda%{matching}'
|
201
|
-
UsesLessOrEqualThan: '%{binding} %{must} utilizar <i>%{operator_LessOrEqualThan}</i>'
|
202
|
-
UsesLessThan: '%{binding} %{must} utilizar <i>%{operator_LessThan}</i>'
|
203
191
|
UsesLogic: '%{binding} %{must} usar operadores booleanos'
|
204
192
|
UsesLoop: '%{binding} %{must} usar um loop%{matching}'
|
205
193
|
UsesMath: '%{binding} %{must} usar expressões matemáticas'
|
206
|
-
UsesMinus: '%{binding} %{must} utilizar <i>%{operator_Minus}</i>'
|
207
194
|
UsesMixins: '%{binding} %{must} usar mixins'
|
208
|
-
|
209
|
-
UsesMultiply: '%{binding} %{must} utilizar <i>%{operator_Multiply}</i>'
|
210
|
-
UsesNegation: '%{binding} %{must} utilizar <i>%{operator_Negation}</i>'
|
211
|
-
UsesNot: '%{binding} %{must} usar <i>%{keyword_Not}</i>'
|
212
|
-
UsesNotEqual: '%{binding} %{must} utilizar <i>%{operator_NotEqual}</i>'
|
195
|
+
UsesNot: '%{binding} %{must} usar <code>%{keyword_Not}</code>'
|
213
196
|
UsesObjectComposition: '%{binding} %{must} usar composição'
|
214
|
-
UsesOr: '%{binding} %{must} utilizar <i>%{operator_Or}</i>'
|
215
|
-
UsesOtherwise: '%{binding} %{must} utilizar <i>%{operator_Otherwise}</i>'
|
216
197
|
UsesPatternMatching: '%{binding} %{must} usar o padrão de correspondência'
|
217
|
-
|
218
|
-
|
219
|
-
UsesRepeatOf: '%{binding} %{must} usar uma <i>%{keyword_Repeat}</i> de %{target}'
|
198
|
+
UsesRepeat: '%{binding} %{must} usar <code>%{keyword_Repeat}</code>%{matching}'
|
199
|
+
UsesRepeatOf: '%{binding} %{must} usar uma <code>%{keyword_Repeat}</code> de %{target}'
|
220
200
|
UsesStaticMethodOverload: '%{binding} %{must} usar sobrecarga'
|
221
201
|
UsesStaticPolymorphism: '%{binding} %{must} usar polimorfismo'
|
222
|
-
UsesSwitch: '%{binding} %{must} usar um <
|
202
|
+
UsesSwitch: '%{binding} %{must} usar um <code>%{keyword_Switch}</code>'
|
223
203
|
UsesTemplateMethod: '%{binding} %{must} usar um _template method_'
|
224
204
|
UsesUnificationOperator: '%{binding} usa o operador de unificação (=)'
|
225
|
-
UsesWhile: '%{binding} %{must} usar um <
|
205
|
+
UsesWhile: '%{binding} %{must} usar um <code>%{keyword_While}</code>%{matching}'
|
data/lib/mulang.rb
CHANGED
@@ -9,16 +9,65 @@ module Mulang
|
|
9
9
|
def self.bin_path
|
10
10
|
File.join(__dir__, '..', 'bin', 'mulang')
|
11
11
|
end
|
12
|
-
def self.analyse(analysis)
|
13
|
-
|
14
|
-
|
12
|
+
def self.analyse(analysis, **options)
|
13
|
+
arg, mode = Mulang::RunMode.for analysis, options
|
14
|
+
Open3.popen2(bin_path, arg) do |input, output, _thread|
|
15
|
+
input.puts mode.input(analysis).to_json
|
15
16
|
input.close
|
16
|
-
JSON.parse output.read
|
17
|
+
result = JSON.parse output.read
|
18
|
+
mode.output result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
module RunMode
|
25
|
+
def self.for(analysis, options)
|
26
|
+
serialization = options[:serialization]
|
27
|
+
many = analysis.is_a?(Array)
|
28
|
+
if many
|
29
|
+
[encode_serialization(serialization), Mulang::RunMode::Natural]
|
30
|
+
elsif serialization
|
31
|
+
[encode_serialization(serialization), Mulang::RunMode::ForcedMany]
|
32
|
+
else
|
33
|
+
["-s", Mulang::RunMode::Natural]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.encode_serialization(option)
|
38
|
+
case option
|
39
|
+
when nil then '-S'
|
40
|
+
when :bracket then '-B'
|
41
|
+
when :brace then '-C'
|
42
|
+
else raise "Unsupported serialization #{option}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module Natural
|
47
|
+
def self.input(analysis)
|
48
|
+
analysis
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.output(result)
|
52
|
+
result
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module ForcedMany
|
57
|
+
def self.input(analysis)
|
58
|
+
[analysis]
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.output(result)
|
62
|
+
result[0]
|
63
|
+
end
|
17
64
|
end
|
18
65
|
end
|
19
66
|
end
|
20
67
|
|
68
|
+
require_relative './mulang/tokens'
|
21
69
|
require_relative './mulang/inspection'
|
22
70
|
require_relative './mulang/expectation'
|
23
71
|
require_relative './mulang/code'
|
24
72
|
require_relative './mulang/language'
|
73
|
+
require_relative './mulang/sexp'
|
data/lib/mulang/code.rb
CHANGED
@@ -1,24 +1,41 @@
|
|
1
1
|
module Mulang
|
2
2
|
class Code
|
3
|
+
attr_accessor :language, :content
|
3
4
|
def initialize(language, content)
|
4
5
|
@language = language
|
5
6
|
@content = content
|
6
7
|
end
|
7
8
|
|
8
|
-
def
|
9
|
-
@language.
|
9
|
+
def identifiers(**options)
|
10
|
+
@language.identifiers @content, **options
|
11
|
+
end
|
12
|
+
|
13
|
+
def ast(**options)
|
14
|
+
@language.ast @content, **options
|
15
|
+
end
|
16
|
+
|
17
|
+
def ast_analysis(**options)
|
18
|
+
@language.ast_analysis @content, **options
|
19
|
+
end
|
20
|
+
|
21
|
+
def transformed_asts(operations, **options)
|
22
|
+
@language.transformed_asts @content, operations, **options
|
23
|
+
end
|
24
|
+
|
25
|
+
def transformed_asts_analysis(operations, **options)
|
26
|
+
@language.transformed_asts_analysis @content, operations, **options
|
10
27
|
end
|
11
28
|
|
12
29
|
def sample
|
13
30
|
@language.sample @content
|
14
31
|
end
|
15
32
|
|
16
|
-
def analysis(spec)
|
17
|
-
|
33
|
+
def analysis(spec, **options)
|
34
|
+
@language.build_analysis @content, spec, **options
|
18
35
|
end
|
19
36
|
|
20
|
-
def analyse(spec)
|
21
|
-
Mulang.analyse analysis(spec)
|
37
|
+
def analyse(spec, **options)
|
38
|
+
Mulang.analyse analysis(spec), **options
|
22
39
|
end
|
23
40
|
|
24
41
|
def expect(binding='*', inspection)
|
@@ -43,12 +60,25 @@ module Mulang
|
|
43
60
|
native(*args).tap { |it| it.expect('Parses') }
|
44
61
|
end
|
45
62
|
|
46
|
-
def self.external(content, &tool)
|
47
|
-
new Mulang::Language::External.new(&tool), content
|
63
|
+
def self.external(language_name = nil, content, &tool)
|
64
|
+
new Mulang::Language::External.new(language_name, &tool), content
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.analyse_many(codes, spec, **options)
|
68
|
+
run_many(codes, **options) { |it| it.analysis(spec) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.ast_many(codes, **options)
|
72
|
+
run_many(codes, key: 'outputAst', **options) { |it| it.ast_analysis(**options) }
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.transformed_asts_many(codes, operations, **options)
|
76
|
+
run_many(codes, key: 'transformedAsts', **options) { |it| it.transformed_asts_analysis(operations, **options) }
|
48
77
|
end
|
49
78
|
|
50
|
-
def self.
|
51
|
-
|
79
|
+
def self.run_many(codes, key: nil, **options)
|
80
|
+
result = Mulang.analyse(codes.map { |it| yield it }, **options)
|
81
|
+
key ? result.map { |it| it[key] } : result
|
52
82
|
end
|
53
83
|
|
54
84
|
private
|
data/lib/mulang/expectation.rb
CHANGED
@@ -1,48 +1,78 @@
|
|
1
1
|
module Mulang::Expectation
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
LOGIC_SMELLS = %w(
|
3
|
+
HasRedundantReduction
|
4
|
+
UsesCut
|
5
|
+
UsesFail
|
6
|
+
UsesUnificationOperator
|
7
|
+
)
|
8
|
+
|
9
|
+
FUNCTIONAL_SMELLS = %w(
|
10
|
+
HasRedundantGuards
|
11
|
+
HasRedundantParameter
|
12
|
+
ShouldUseOtherwise
|
13
|
+
)
|
14
|
+
|
15
|
+
OBJECT_ORIENTED_SMELLS = %w(
|
5
16
|
DoesNilTest
|
6
17
|
DoesNullTest
|
18
|
+
HasTooManyMethods
|
19
|
+
OverridesEqualOrHashButNotBoth
|
20
|
+
ReturnsNil
|
21
|
+
ReturnsNull
|
7
22
|
DoesTypeTest
|
8
|
-
|
23
|
+
)
|
24
|
+
|
25
|
+
IMPERATIVE_SMELLS = %w(
|
9
26
|
HasAssignmentCondition
|
27
|
+
HasAssignmentReturn
|
28
|
+
HasEmptyRepeat
|
29
|
+
HasRedundantRepeat
|
30
|
+
)
|
31
|
+
|
32
|
+
EXPRESSIVENESS_SMELLS = %w(
|
33
|
+
HasMisspelledBindings
|
34
|
+
HasMisspelledIdentifiers
|
35
|
+
HasTooShortIdentifiers
|
36
|
+
HasWrongCaseBinding
|
37
|
+
HasWrongCaseIdentifiers
|
38
|
+
)
|
39
|
+
|
40
|
+
GENERIC_SMELLS = %w(
|
41
|
+
DiscardsExceptions
|
42
|
+
DoesConsolePrint
|
10
43
|
HasCodeDuplication
|
11
44
|
HasDeclarationTypos
|
12
45
|
HasEmptyIfBranches
|
13
|
-
|
46
|
+
HasEqualIfBranches
|
14
47
|
HasLongParameterList
|
15
|
-
HasMisspelledBindings
|
16
|
-
HasMisspelledIdentifiers
|
17
48
|
HasRedundantBooleanComparison
|
18
|
-
|
49
|
+
HasRedundantLocalVariableReturn
|
19
50
|
HasRedundantIf
|
20
51
|
HasRedundantLambda
|
21
|
-
HasRedundantLocalVariableReturn
|
22
|
-
HasRedundantParameter
|
23
|
-
HasRedundantReduction
|
24
|
-
HasRedundantRepeat
|
25
|
-
HasTooManyMethods
|
26
52
|
HasTooShortBindings
|
27
|
-
HasTooShortIdentifiers
|
28
53
|
HasUnreachableCode
|
29
54
|
HasUsageTypos
|
30
|
-
HasWrongCaseBinding
|
31
|
-
HasWrongCaseIdentifiers
|
32
55
|
IsLongCode
|
33
|
-
OverridesEqualOrHashButNotBoth
|
34
|
-
ReturnsNil
|
35
|
-
ReturnsNull
|
36
56
|
ShouldInvertIfCondition
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
57
|
+
ShouldUseStrictComparators
|
58
|
+
)
|
59
|
+
|
60
|
+
JAVA_SCRIPT_SMELLS = %w(
|
61
|
+
JavaScript#UsesVarInsteadOfLet
|
62
|
+
)
|
63
|
+
|
64
|
+
SMELLS = GENERIC_SMELLS +
|
65
|
+
EXPRESSIVENESS_SMELLS +
|
66
|
+
IMPERATIVE_SMELLS +
|
67
|
+
OBJECT_ORIENTED_SMELLS +
|
68
|
+
FUNCTIONAL_SMELLS +
|
69
|
+
LOGIC_SMELLS +
|
70
|
+
JAVA_SCRIPT_SMELLS
|
41
71
|
|
42
72
|
def self.guess_type(expectation)
|
43
73
|
if expectation[:binding] == '<<custom>>'
|
44
74
|
Custom
|
45
|
-
elsif expectation[:inspection] =~
|
75
|
+
elsif expectation[:inspection] =~ /^(Not\:)?Has.*/ && !has_smell?(expectation[:inspection])
|
46
76
|
V0
|
47
77
|
else
|
48
78
|
V2
|
@@ -1,47 +1,5 @@
|
|
1
1
|
module Mulang::Expectation::I18n
|
2
2
|
class << self
|
3
|
-
DEFAULT_TOKENS = {
|
4
|
-
keyword_EntryPoint: 'program',
|
5
|
-
keyword_Fail: 'fail',
|
6
|
-
keyword_False: 'false',
|
7
|
-
keyword_findall: 'findall',
|
8
|
-
keyword_For: 'for',
|
9
|
-
keyword_Forall: 'forall',
|
10
|
-
keyword_Foreach: 'foreach',
|
11
|
-
keyword_If: 'if',
|
12
|
-
keyword_Is: 'is',
|
13
|
-
keyword_Not: 'not',
|
14
|
-
keyword_Null: 'null',
|
15
|
-
keyword_Repeat: 'repeat',
|
16
|
-
keyword_Switch: 'switch',
|
17
|
-
keyword_True: 'true',
|
18
|
-
keyword_While: 'while',
|
19
|
-
keyword_Yield: 'yield',
|
20
|
-
operator_And: '&&',
|
21
|
-
operator_BackwardComposition: '.',
|
22
|
-
operator_Divide: '/',
|
23
|
-
operator_Equal: '==',
|
24
|
-
operator_ForwardComposition: '>>',
|
25
|
-
operator_GreatherOrEqualThan: '>=',
|
26
|
-
operator_GreatherThan: '>',
|
27
|
-
operator_Hash: 'hash',
|
28
|
-
operator_LessOrEqualThan: '<=',
|
29
|
-
operator_LessThan: '<',
|
30
|
-
operator_Minus: '-',
|
31
|
-
operator_Multiply: '*',
|
32
|
-
operator_Negation: '!',
|
33
|
-
operator_NotEqual: '!=',
|
34
|
-
operator_Or: '||',
|
35
|
-
operator_Otherwise: 'otherwise',
|
36
|
-
operator_Plus: '+',
|
37
|
-
operator_Modulo: '%',
|
38
|
-
operator_BitwiseOr: '|',
|
39
|
-
operator_BitwiseAnd: '&',
|
40
|
-
operator_BitwiseXor: '^',
|
41
|
-
operator_BitwiseLeftShift: '<<',
|
42
|
-
operator_BitwiseRightShift: '>>'
|
43
|
-
}.transform_values { |v| CGI::escapeHTML(v) }.freeze
|
44
|
-
|
45
3
|
def translate(e, tokens = nil)
|
46
4
|
translate!(e, tokens)
|
47
5
|
rescue
|
@@ -71,7 +29,7 @@ module Mulang::Expectation::I18n
|
|
71
29
|
end
|
72
30
|
|
73
31
|
def t_binding(binding)
|
74
|
-
binding == '*' ? ::I18n.t("mulang.expectation.solution") : "<
|
32
|
+
binding == '*' ? ::I18n.t("mulang.expectation.solution") : "<code>#{Mulang::Inspection.parse_binding_name binding}</code>"
|
75
33
|
end
|
76
34
|
|
77
35
|
def t_must(parsed)
|
@@ -79,7 +37,7 @@ module Mulang::Expectation::I18n
|
|
79
37
|
end
|
80
38
|
|
81
39
|
def t_target(parsed)
|
82
|
-
"<
|
40
|
+
"<code>#{parsed.target.value}</code>" if parsed.target
|
83
41
|
end
|
84
42
|
|
85
43
|
def t_matching(tokens, parsed)
|
@@ -87,7 +45,15 @@ module Mulang::Expectation::I18n
|
|
87
45
|
end
|
88
46
|
|
89
47
|
def with_tokens(tokens, params)
|
90
|
-
|
48
|
+
hash = if tokens.nil?
|
49
|
+
{}
|
50
|
+
elsif tokens.is_a?(Hash)
|
51
|
+
tokens
|
52
|
+
else
|
53
|
+
params.merge(Mulang::Tokens::TOKENS.indifferent_get(tokens))
|
54
|
+
end
|
55
|
+
|
56
|
+
params.merge(Mulang::Tokens::DEFAULT_TOKENS.merge(hash))
|
91
57
|
end
|
92
58
|
end
|
93
59
|
end
|