๐Ÿ“ฆ n8n-io / nodelinter

Static code analyzer for n8n node files

โ˜… 16 stars โ‘‚ 7 forks ๐Ÿ‘ 16 watching โš–๏ธ MIT License
n8n
๐Ÿ“ฅ Clone https://github.com/n8n-io/nodelinter.git
HTTPS git clone https://github.com/n8n-io/nodelinter.git
SSH git clone git@github.com:n8n-io/nodelinter.git
CLI gh repo clone n8n-io/nodelinter
Ivรกn Ovejero Ivรกn Ovejero Merge pull request #49 from n8n-io/lint-toplevel-required-fixed-collection c04f812 4 years ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ .vscode
๐Ÿ“ src
๐Ÿ“„ .gitignore
๐Ÿ“„ .npmignore
๐Ÿ“„ .prettierignore
๐Ÿ“„ .prettierrc
๐Ÿ“„ jest.config.js
๐Ÿ“„ LICENSE.md
๐Ÿ“„ package-lock.json
๐Ÿ“„ package.json
๐Ÿ“„ README.md
๐Ÿ“„ tsconfig.json
๐Ÿ“„ README.md

Nodelinter

Static code analyzer for n8n node files
by Ivรกn Ovejero


Nodelinter is a static code analyzer for n8n node files, with ~70 linting rules for:

  • default values based on param type,
  • casing for display names and descriptions,
  • alphabetization for params and options,
  • required and optional key-value pairs,
  • expected values for specific params,
  • etc.
See full lintings list.

Operation

Run via npx:

npx nodelinter --target=/Users/john/n8n/packages/nodes-base/nodes/Stripe/Stripe.node.ts

Or run locally:

git clone https://github.com/n8n-io/nodelinter
cd nodelinter; npm i
npm run lint -- --target=/Users/john/n8n/packages/nodes-base/nodes/Stripe/Stripe.node.ts

Options

OptionEffect
--targetPath of the file or directory to lint
--configPath of the custom config to use
--printWhether to print output to lintOutput.json
--patternsLintable file patterns
--errors-onlyEnable error logs only
--warnings-onlyEnable warning logs only
--infos-onlyEnable info logs only
Examples:

# lint a single file
--target=./packages/nodes-base/nodes/Stripe/Stripe.node.ts

# lint all files in a dir
--target=./packages/nodes-base/nodes/Stripe

# use a custom config
--config=/Users/john/Documents/myConfig.json

# print logs to lintOutput.json
--print

# lint files ending with these patterns
--target=./src/input/MyNode --patterns:.node.ts,Description.ts

# lint files ending with this pattern
--target=./src/input/MyNode --patterns:.node.ts

# lint only rules with error classification
--target=./src/input/MyNode --errors-only

Custom config

You can override the Nodelinter default config with a custom config.

To do so, create a JSON file containing any keys to overwrite:

{
  "target": "/Users/john/n8n/packages/nodes-base/nodes/Notion/Notion.node.ts",
  "patterns": [".node.ts"],
  "sortMethod": "lineNumber",
  "lintings": {
    "PARAM_DESCRIPTION_MISSING_WHERE_OPTIONAL": {
      "enabled": false
    },
    "NAME_WITH_NO_CAMELCASE": {
      "enabled": false
    }
  }
}

And use the --config option:

npx nodelinter --config=/Users/john/Documents/myConfig.json

For convenience, when running locally, if you place a custom config file named nodelinter.config.json anywhere inside the nodelinter dir, the custom config file will be auto-detected.

Lint exceptions

Add // nodelinter-ignore-next-line LINTING_NAME to except the next line from one or more specific lintings:

// nodelinter-ignore-next-line PARAM_DESCRIPTION_WITH_EXCESS_WHITESPACE
description: 'Time zone used in the response.    The default is the time zone of the calendar.',

// nodelinter-ignore-next-line PARAM_DESCRIPTION_WITH_EXCESS_WHITESPACE PARAM_DESCRIPTION_UNTRIMMED
description: 'Time zone used in the response.    The default is the time zone of the calendar.   ',

Or add // nodelinter-ignore-next-line to except the next line from all lintings:

// nodelinter-ignore-next-line
description: 'Time zone used in the response.    The default is the time zone of the calendar.',

Author

ยฉ 2021 Ivรกn Ovejero

License

Distributed under the MIT License.