summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authordzwdz2021-07-10 20:10:37 +0200
committerdzwdz2021-07-10 20:10:37 +0200
commit2c3de0bdb63f933fecf7cf717396a16a29e38e10 (patch)
treedde96841cb6d086beccb77a90a80d0efd4ff51d2 /tools
parenta90f613e50b1677b03d19793039e0769a09caf9f (diff)
implement a basic linter
Currently it just checks if the kernel doesn't accidentally use arch-dependent headers.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/linter/main.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/tools/linter/main.rb b/tools/linter/main.rb
new file mode 100755
index 0000000..1198fd1
--- /dev/null
+++ b/tools/linter/main.rb
@@ -0,0 +1,28 @@
+#!/usr/bin/env ruby
+# must be run in the root directory of the repo
+# currently it only checks if code in src/kernel/ uses anything arch-dependent
+
+$return = 0
+
+def warn(msg)
+ STDERR.puts "[LINTER] #{msg}"
+ $return = 1
+end
+
+whitelist = ["arch/generic.h"]
+
+Dir["src/kernel/**.?"]
+ .each do |path|
+ File.read(path)
+ .lines
+ .map(&:strip) # strip whitespace
+ .filter{|line| line[0] == '#'} # find preprocessor directives
+ .map{|line| line[1..].strip} # get rid of the #, strip again
+ .filter{|l| l.start_with? "include"} # find includes
+ .map{|l| /([<"](.+)[">])/.match(l)[2]} # get the name of the included file
+ .filter{|l| l.start_with? "arch/"} # find files in arch/
+ .filter{|l| not whitelist.include? l} # filter out whitelisted headers
+ .each{|inc| warn "#{path} includes #{inc}"}
+ end
+
+exit $return