Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / nitpick.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # A program that collect potential style and code issues
16 module nitpick
17
18 import frontend
19 import doc::vim_autocomplete
20
21 redef class ToolContext
22 # Modules to analyze, other modules will only get a shallow processing.
23 var mmodules_to_check = new HashSet[MModule]
24 redef fun phase_process_npropdef(phase, npropdef)
25 do
26 var pd = npropdef.mpropdef
27
28 # Do not analyze the property bodies outside specified modules
29 if pd != null and not mmodules_to_check.has(pd.mclassdef.mmodule) then return
30 super
31 end
32 end
33
34 # Create a tool context to handle options and paths
35 var toolcontext = new ToolContext
36 toolcontext.tooldescription = "Usage: nitpick [OPTION]... <file.nit>...\nCollect potential style and code issues."
37
38 # We do not add other options, so process them now!
39 toolcontext.process_options(args)
40
41 # Do not stop phases on errors
42 toolcontext.keep_going = true
43
44 # Get arguments
45 var arguments = toolcontext.option_context.rest
46
47 # We need a model to collect stuffs
48 var model = new Model
49 # A model builder to parse files
50 var modelbuilder = new ModelBuilder(model, toolcontext)
51
52 # Here we load and process all modules passed on the command line
53 var mmodules = modelbuilder.parse_full(arguments)
54 toolcontext.mmodules_to_check.add_all mmodules
55
56 # Blacklist warnings of not explicitly required modules
57 for mm in model.mmodules do
58 if mmodules.has(mm) then continue
59 toolcontext.warning_blacklist[mm.location.file].add("all")
60 end
61
62 modelbuilder.run_phases
63 toolcontext.run_global_phases(mmodules)
64 if toolcontext.error_count > 0 then exit(1)