Update style check action

This commit is contained in:
Christian W. Zuckschwerdt 2020-09-18 20:58:08 +02:00
commit 2fcaa47ee1

View file

@ -48,22 +48,15 @@ function glob_dir(dir) {
function style_check(filename) {
const strict = filename.indexOf('/devices/') >= 0
const txt = filename.endsWith('.txt')
let read_errors = 0
let long_errors = 0
let crlf_errors = 0
let tabs_errors = 0
let trailing_errors = 0
let memc_errors = 0
let funbrace_errors = 0
let errors = 0
let leading_tabs = 0
let leading_spcs = 0
let use_stdout = 0
let use_printf = 0
let mixed_ws = 0
let need_cond = 0
let line_number = 0
fs.readFileSync(filename, 'ascii')
@ -73,15 +66,15 @@ function style_check(filename) {
const len = line.length
if (len < 0) {
log(`::error file=${filename},line=${line_number},col=${len-1}::READ error`)
read_errors++
errors++
}
if (len >= MAX_LEN - 1) {
log(`::error file=${filename},line=${line_number},col=${len-1}::LONG line error`)
long_errors++
errors++
}
if (line[len - 1] == '\r' || (len > 1 && line[len - 2] == '\r')) {
log(`::error file=${filename},line=${line_number},col=${len-1}::CRLF error`)
crlf_errors++
errors++
}
if (line[0] == '\t') {
@ -93,28 +86,37 @@ function style_check(filename) {
}
if (line[len - 1] == ' ' || line[len - 1] == '\t') {
log(`::error file=${filename},line=${line_number},col=${len-1}::TRAILING whitespace error`)
trailing_errors++
errors++
}
if (line.indexOf('(r_device *decoder') >= 0 && line[len - 1] == '{') {
log(`::error file=${filename},line=${line_number},col=${len-1}::BRACE function on newline error`)
funbrace_errors++
errors++
}
if (line.indexOf('){') >= 0 && line.indexOf('}') < 0) {
log(`::error file=${filename},line=${line_number},col=${len - 1}::STICKY-BRACE error`)
errors++
}
if (!txt && (line.indexOf('if(') >= 0 || line.indexOf('for(') >= 0 || line.indexOf('while(') >= 0)) {
log(`::error file=${filename},line=${line_number},col=${len - 1}::STICKY-PAREN error`)
errors++
}
if (strict && line.indexOf('stdout') >= 0) {
log(`::error file=${filename},line=${line_number},col=${len - 1}::STDOUT line`)
use_stdout++
errors++
}
const p = line.indexOf('printf')
if (strict && p >= 0) {
if (p == 0 || line[p-1] < '_' || line[p-1] > 'z') {
log(`::error file=${filename},line=${line_number},col=${len - 1}::PRINTF line`)
use_printf++
errors++
}
}
if (need_cond && line.indexOf('if (!') < 0) {
// we had an alloc but no check on the following line
log(`::error file=${filename},line=${line_number},col=${len - 1}::ALLOC check error`)
memc_errors++
errors++
}
need_cond = 0
if (line.indexOf('alloc(') >= 0 && line.indexOf('alloc()') < 0) {
@ -127,10 +129,9 @@ function style_check(filename) {
})
if (leading_tabs && leading_spcs) {
log(`::error file=${filename}::${tabs_errors} MIXED tab/spaces errors.`)
tabs_errors = leading_tabs > leading_spcs ? leading_spcs : leading_tabs
mixed_ws = leading_tabs > leading_spcs ? leading_spcs : leading_tabs
log(`::error file=${filename}::${mixed_ws} MIXED tab/spaces errors.`)
}
return read_errors + long_errors + crlf_errors + tabs_errors + leading_tabs + trailing_errors
+ funbrace_errors + use_stdout + use_printf + memc_errors
return errors + mixed_ws + leading_tabs
}