/[eiffelstudio]/branches/eth/eve/Src/framework/code_analysis/rules/paolo/ca_argument_naming_convention_rule.e
ViewVC logotype

Contents of /branches/eth/eve/Src/framework/code_analysis/rules/paolo/ca_argument_naming_convention_rule.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94865 - (show annotations)
Wed Apr 16 16:18:27 2014 UTC (5 years, 6 months ago) by apaolo
File size: 3085 byte(s)
Improved rules about naming conventions: they are now able to actually check the identifiers' case.
1 note
2 description: "[
3 RULE #66: Argument naming convention violated
4
5 Argument names should respect the Eiffel naming convention for arguments
6 (all lowercase begin with 'a_', no trailing or two consecutive underscores).
7 ]"
8 author: "Paolo Antonucci"
9 date: "$Date$"
10 revision: "$Revision$"
11
12 class
13 CA_ARGUMENT_NAMING_CONVENTION_RULE
14
15 inherit
16
17 CA_STANDARD_RULE
18
19 create
20 make
21
22 feature {NONE} -- Initialization
23
24 make
25 -- Initialization for `Current'.
26 do
27 make_with_defaults
28 end
29
30 feature {NONE} -- Activation
31
32 register_actions (a_checker: attached CA_ALL_RULES_CHECKER)
33 do
34 a_checker.add_body_pre_action (agent process_body)
35 end
36
37 feature {NONE} -- Rule checking
38
39 process_body (a_body_as: attached BODY_AS)
40 local
41 l_viol: CA_RULE_VIOLATION
42 l_construct_list: CONSTRUCT_LIST [INTEGER_32]
43 l_leaf: LEAF_AS
44 l_argument_name: STRING
45 do
46 -- It's a bit more complicated that one would expect, because retrieving the original
47 -- text is the only way for checking the case (otherwise it's always lowercased).
48 -- This code is basically copy-pasted in this class and in CA_VARIABLE_NAMING_CONVENTION.
49 -- Copy-pasting is bad, but creating a common ancestor just for these two rules is also bad.
50 -- Edits here should be also made there.
51 -- Whoever copy-pastes this a third time should consider refactoring the code.
52 if a_body_as.arguments /= Void then
53 across
54 a_body_as.arguments as arguments
55 loop
56 l_construct_list := arguments.item.id_list.id_list
57 across
58 l_construct_list as l_id
59 loop
60 l_leaf := current_context.matchlist.at (l_id.item)
61 l_argument_name := l_leaf.text_32 (current_context.matchlist)
62 if not is_valid_argument_name (l_argument_name) then
63 create l_viol.make_with_rule (Current)
64 l_viol.set_location (l_leaf.start_location)
65 l_viol.long_description_info.extend (l_argument_name)
66 violations.extend (l_viol)
67 end
68 end
69 end
70 end
71 end
72
73 is_valid_argument_name (a_name: attached STRING): BOOLEAN
74 -- Currently the casing restriction cannot be enforced, as identifiers received by this
75 -- function are always upper- or lower-cased.
76 do
77 Result := not a_name.ends_with ("_") and not a_name.has_substring ("__") and (a_name.as_lower ~ a_name) and a_name.starts_with ("a_")
78 end
79
80 feature -- Properties
81
82 title: STRING_32
83 do
84 Result := ca_names.argument_naming_convention_title
85 end
86
87 id: STRING_32 = "CA066"
88 -- <Precursor>
89
90 description: STRING_32
91 do
92 Result := ca_names.argument_naming_convention_description
93 end
94
95 format_violation_description (a_violation: attached CA_RULE_VIOLATION; a_formatter: attached TEXT_FORMATTER)
96 do
97 a_formatter.add (ca_messages.argument_naming_convention_violation_1)
98 check attached {STRING} a_violation.long_description_info.first as arg_name then
99 a_formatter.add (arg_name)
100 end
101 a_formatter.add (ca_messages.argument_naming_convention_violation_2)
102 end
103
104 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23