Categories &

Functions List

Function Reference: devtools.styleLint

devtools: devtools.styleLint (TARGET)

devtools: devtools.styleLint (TARGET, RULES)

devtools: R = devtools.styleLint (…)

Check code against the layout rules of the Octave packages’ coding style.

devtools.styleLint (TARGET) prints every line that breaks one of the rules below. TARGET is one file, the folder a package’s source is in, or the name of an installed package.

devtools.styleLint (TARGET, RULES) checks only the rules named in RULES, a cell array of character vectors. The rules are one maintainer’s style rather than anything Octave requires, so each can be left out.

R = devtools.styleLint (…) prints nothing and returns the findings as a structure array holding file, line, column, rule and message, empty where there is nothing to report. Columns count characters.

The test blocks are code too: a line opening with %! is checked as the code after its %! prefix, and the body of a %!function block as the code after %!, its header sitting there.

'tab'
A tab character anywhere, inside a string too, where \t says it plainly.
'indent'
Two spaces per level of nesting. A case sits two spaces inside its switch and its body four; else, elseif, catch, unwind_protect_cleanup and until sit at the level of the line that opened their block. A comment line takes the level of the next line of code, or the level of its own block where that line closes or continues the block, as a comment standing alone in a case does. A section banner, a comment spanning the page from column one, is exempt. A line continuing a statement is not checked, whether ... continues it or an open bracket does.
'quote'
Single quotes are the default for a string. Double quotes are for the strings passed to error, warning, printf, fprintf and sprintf, and those are always double, the strings of a [] or a strcat building one included. The double quotes are for the message text, so the strings of a warning state call, warning ('off', id) and the like, are single. A double-quoted string holding a backslash escape is accepted anywhere, having no single-quoted spelling.
'length'
A line longer than 80 columns. The lines of a texinfo block are left to devtools.docLint, and the header of an %!error or %!warning block is exempt, the message it expects having nowhere to break.
'condition'
The condition of if, elseif, while and until, or the value of switch, not in parentheses; or a condition running over a line with ..., the parentheses continuing it already.

A file that does not parse is reported once as 'syntax', with the line that stopped it, in place of the rules that read the syntax tree: 'indent', 'quote' and 'condition'. The test blocks are parsed apart from the code, so either can fail alone.

The parser is a compiled file, so this raises where the package was installed without a working compiler and a rule reading the syntax tree is asked for.

See also: devtools.dialectLint, devtools.docLint

Source Code: devtools.styleLint