Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Linter messages

The linter reads your worksheet while you type and marks problems before you run it. Each mark carries a code that starts with CPD-, such as CPD-3301, and a message. This page lists the codes and what to do about each.

What it checks and where it shows

The linter looks at the whole worksheet, including the files it pulls in with #include, and checks these: #include lines, macro definitions, brackets and blocks, names (variables, functions, macros, units) and how they are used, and the metadata comments and #UI lines. It works on a sheet too: the sheet is turned into a Calcpad worksheet first, and the marks are shown on your sheet lines.

It runs about half a second after you stop typing, and again when you switch tabs or refresh. You see it in three places:

  • Underlines in the source: red for an error, yellow for a warning, blue for information. Hover over one to read the code and the message.
  • The Errors dialog (Errors and warnings), from the ribbon or the status bar, lists the marks of the open file.
  • The status bar shows the number of errors, warnings and information marks.

The linter runs in the editor only. The command-line Cli and the engine do not lint, so a worksheet that has lint marks can still calculate, and some errors that the engine reports (an undefined name, say) are also caught by the linter before you run.

Choosing how much to show

Settings > Editor > Linter Minimum Severity has three choices: Error, Warning and Information (all). A mark below the level you choose is hidden, from the underlines and from the Errors dialog alike. The default is Information (all). Changing it takes effect at once.

Most worksheets show many CPD-3312 marks at the default, because every value you calculate and never use again counts as unused. Set the minimum to Warning to hide them.

Reading a message

A message has the text of the code, then a colon and a detail about your line, for example Undefined variable: 'zz'. The tables below give the text of each code. Where the detail is a name or a count from your line, it is not repeated here.

Includes

CodeSeverityMessageFix
CPD-1101ErrorMalformed #include statementWrite #include name.cpd.
CPD-1102ErrorMissing #include filenameAdd the file after #include.
CPD-1103WarningDeprecated #include input valuesRemove the #{...} values and declare the inputs with #UI in the included file.

Macros

CodeSeverityMessageFix
CPD-2201ErrorDuplicate macro definitionRename one of them or delete the second.
CPD-2202ErrorMacro name must end with ‘$’Write #def name$.
CPD-2203ErrorMacro parameter must end with ‘$’Write p$ in the parameter list.
CPD-2204ErrorInvalid macro name (must start with a letter)Start the name with a letter.
CPD-2205ErrorMalformed #def syntaxWrite #def name$ or #def name$(p1$; p2$).
CPD-2206ErrorUnmatched #def or #end defPair every #def with an #end def.
CPD-2207ErrorNested macro definition not allowedClose the first macro before starting the next.
CPD-2208ErrorMacro parameter must start with a letterStart the parameter with a letter.
CPD-2209WarningMacro definition inside a control block has no effectMove the #def out of the #if or loop.
CPD-2210ErrorInvalid character in macro nameUse ASCII letters, digits and underscores.
CPD-2211ErrorInvalid character in macro parameterUse ASCII letters, digits and underscores.
CPD-2212ErrorDuplicate macro parameterGive each parameter its own name.
CPD-2213ErrorRequired parameter after optional parameterPut the optional parameters last.

Brackets and blocks

CodeSeverityMessageFix
CPD-3101ErrorUnmatched opening parenthesisAdd the closing ).
CPD-3102ErrorUnmatched closing parenthesisRemove it or add the opening (.
CPD-3103ErrorUnmatched opening square bracketAdd the closing ].
CPD-3104ErrorUnmatched closing square bracketRemove it or add the opening [.
CPD-3105ErrorUnmatched opening curly brace or control blockAdd the closing }, or the #end if or #loop of the block.
CPD-3106ErrorUnmatched closing curly braceRemove it or add the opening {.

Names

CodeSeverityMessageFix
CPD-3201ErrorInvalid variable name (must start with a letter)Start the name with a letter.
CPD-3202ErrorInvalid function nameStart the name with a letter.
CPD-3203ErrorFunction name conflicts with a built-in functionPick another name.
CPD-3204ErrorVariable name conflicts with a keywordPick another name.
CPD-3205WarningVariable name conflicts with a built-in constantPick another name.
CPD-3206ErrorFunction must have at least one parameterAdd a parameter, or make it a variable.
CPD-3207ErrorRequired parameter after optional parameter in function definitionPut the optional parameters last.

Usage

CodeSeverityMessageFix
CPD-3301ErrorUndefined variableDefine it above the line, or fix the spelling.
CPD-3302ErrorFunction called with the wrong number of parametersMatch the number in the definition.
CPD-3303ErrorUndefined macroDefine it with #def above the line.
CPD-3304ErrorMacro called with the wrong number of parametersMatch the number in the definition.
CPD-3305ErrorUndefined functionDefine it above the line, or fix the spelling.
CPD-3306WarningInvalid element accessIndex only vectors and matrices.
CPD-3307ErrorToo few parametersAdd the missing arguments of the built-in function.
CPD-3308ErrorToo many parametersRemove the extra arguments.
CPD-3309WarningParameter type mismatchPass a value of the type the function expects.
CPD-3310ErrorUndefined unitFix the unit name; see Units.
CPD-3311ErrorEmpty parameter in a function callFill in the empty argument or delete its ;.
CPD-3312InformationUnused variableUse the value, or ignore the mark.
CPD-3313InformationRedefinition of existing functionRename one of the functions.
CPD-3314ErrorUnknown keyword argumentUse a parameter name from the macro.
CPD-3315ErrorUnknown keyword argument in function callUse a parameter name from the function.

Semantics

CodeSeverityMessageFix
CPD-3401ErrorInvalid operator usageReplace operators such as ++, which Calcpad does not have.
CPD-3402ErrorUnknown command nameCheck the spelling of the $ command.
CPD-3403ErrorUnknown directiveCheck the spelling of the # directive.
CPD-3404WarningInvalid assignment (multiple assignments on the same line)Put each assignment on its own line.
CPD-3405Error# directive not allowed inside a command blockUse if(), $Repeat and the like inside the braces.
CPD-3406ErrorInvalid command syntaxWrite @ variable = start : end.
CPD-3407ErrorIncomplete expressionFinish the right-hand side.
CPD-3408ErrorCommand variable mismatchUse the loop variable the command declares.
CPD-3409ErrorReassignment of a constantDo not assign to a name you defined as a constant.
CPD-3410ErrorOuter-scope assignment (←) to an undefined variableDefine the variable before the block.

Metadata comments, #settings and #UI

CodeSeverityMessageFix
CPD-3411WarningInvalid paramType value in a metadata commentUse a value the comment accepts.
CPD-3412WarningInvalid metadata-comment JSONFix the JSON, or the unknown property name.
CPD-3413WarningInvalid #settings JSONFix the JSON after #settings.
CPD-3414WarningInvalid PDF settings in a metadata commentCheck the PDF properties.
CPD-3415WarningInvalid #UI formatWrite #UI with a variable assignment.
CPD-3416Warning‘uiOverrides’ metadata comment not on the first lineMove it to the first line of the file.
CPD-3417WarningDuplicate ‘uiOverrides’ metadata commentKeep one; only the first is read.
CPD-3418Warning‘uiOverrides’ sharing a comment with another keyGive uiOverrides a comment of its own.
CPD-3419WarningDeprecated stored input valueReplace ?{...} with #UI.
CPD-3601WarningInvalid format specifierUse a format of the form the #format directive takes.
CPD-3801ErrorThe #python block has no ‘#end python’ lineClose the block; see Python.

Examples

Most of these marks match an error the engine gives when you run the worksheet. A line the engine rejects is shown as text, then the corrected version as a worksheet.

An undefined name (CPD-3301). The engine says Undefined variable or units: "zz":

q = zz + 1
zz = 2
q = zz + 1

The wrong number of arguments (CPD-3302). The engine says Invalid number of arguments:

f(x; y) = x + y
z = f(1)
f(x; y) = x + y
z = f(1; 2)

A bracket left open (CPD-3101). The engine says Missing right bracket ")":

x = (1 + 2
x = (1 + 2)

A unit the engine does not know (CPD-3310). It says Error parsing "foo" as units:

a = 3 foo
a = 3 m

A macro defined twice (CPD-2201). The engine says Duplicate macro name: "m$":

#def m$
    1
#end def
#def m$
    2
#end def
#def m$
    1
#end def
m$

A name the engine reserves (CPD-3203, CPD-3205, CPD-3409). Defining your own sin gives "sin" is a built-in function and cannot be redefined, and assigning to π gives Cannot modify constant "π":

sin(x) = x
π = 3
y = sin(30)

Silencing a message

Wrap the lines in a pair of metadata comments. LintIgnore lists the codes to hide from that line on, and EndLintIgnore ends the region. Codes are not case sensitive.

'<!--{"LintIgnore": ["CPD-3312"]}-->
x = 1
'<!--{"EndLintIgnore": []}-->
  • An empty list, "LintIgnore": [], hides every code until the matching EndLintIgnore.
  • EndLintIgnore with codes ends just those; with an empty list it ends all open regions.
  • A region left open runs to the end of the file.

Suppression hides the mark only. It does not change the calculation, so wrapping a line that the engine rejects, such as q = zz, still gives the engine’s error when you run it. The comments are printed in the results as ordinary text comments.

See also