Agent Skillsn8n-io/n8n › n8n:create-community-node-lint-rule

n8n:create-community-node-lint-rule

GitHub

指导为n8n社区节点ESLint插件创建新的Lint规则。涵盖规则设计、TypeScript实现、测试编写及文档注册,提供AST工具使用示例和代码模板。

.agents/skills/create-community-node-lint-rule/SKILL.md n8n-io/n8n

触发场景

添加新的ESLint规则 创建社区节点lint检查 修改eslint-plugin-community-nodes

安装

npx skills add n8n-io/n8n --skill n8n:create-community-node-lint-rule -g -y
更多选项

非标准路径

npx skills add https://github.com/n8n-io/n8n/tree/master/.agents/skills/create-community-node-lint-rule -g -y

不安装直接使用

npx skills use n8n-io/n8n@n8n:create-community-node-lint-rule

指定 Agent (Claude Code)

npx skills add n8n-io/n8n --skill n8n:create-community-node-lint-rule -a claude-code -g -y

安装 repo 全部 skill

npx skills add n8n-io/n8n --all -g -y

预览 repo 内 skill

npx skills add n8n-io/n8n --list

SKILL.md

Frontmatter
{
    "name": "n8n:create-community-node-lint-rule",
    "description": "Create new ESLint rules for the @n8n\/eslint-plugin-community-nodes package. Use when adding a lint rule, creating a community node lint, or working on eslint-plugin-community-nodes. Guides rule implementation, tests, docs, and plugin registration."
}

Create Community Node Lint Rule

Guide for adding new ESLint rules to packages/@n8n/eslint-plugin-community-nodes/.

All paths below are relative to packages/@n8n/eslint-plugin-community-nodes/.

Step 1: Understand the Rule

Before writing code, clarify:

  • What does the rule detect? (missing property, wrong pattern, bad value)
  • Where does it apply? (.node.ts files, credential classes, both)
  • Severity: error (must fix) or warn (should fix)?
  • Fixable? Can it be auto-fixed safely, or only suggest?
  • Scope: Both recommended configs, or exclude from recommendedWithoutN8nCloudSupport?

Step 2: Implement the Rule

Create src/rules/<rule-name>.ts:

import { AST_NODE_TYPES } from '@typescript-eslint/utils';

import {
  isNodeTypeClass,       // or isCredentialTypeClass
  findClassProperty,
  findObjectProperty,
  createRule,
} from '../utils/index.js';

export const YourRuleNameRule = createRule({
  name: 'rule-name',
  meta: {
    type: 'problem',  // or 'suggestion'
    docs: {
      description: 'One-line description of what the rule enforces',
    },
    messages: {
      messageId: 'Human-readable message. Use {{placeholder}} for dynamic data.',
    },
    fixable: 'code',     // omit if not auto-fixable
    hasSuggestions: true, // omit if no suggestions
    schema: [],           // add options schema if configurable
  },
  defaultOptions: [],
  create(context) {
    return {
      ClassDeclaration(node) {
        if (!isNodeTypeClass(node)) return;

        const descriptionProperty = findClassProperty(node, 'description');
        if (!descriptionProperty) return;

        const descriptionValue = descriptionProperty.value;
        if (descriptionValue?.type !== AST_NODE_TYPES.ObjectExpression) return;

        // Rule logic here — use findObjectProperty(), getLiteralValue(), etc.

        context.report({
          node: targetNode,
          messageId: 'messageId',
          data: { /* template vars */ },
          fix(fixer) {
            return fixer.replaceText(targetNode, 'replacement');
          },
        });
      },
    };
  },
});

Naming: Export as PascalCaseRule (e.g. MissingPairedItemRule). The name field is kebab-case.

Available AST helpers — see reference.md for the full catalog of ast-utils and file-utils exports.

Step 3: Write Tests

Create src/rules/<rule-name>.test.ts:

import { RuleTester } from '@typescript-eslint/rule-tester';

import { YourRuleNameRule } from './rule-name.js';

const ruleTester = new RuleTester();

// Helper to generate test code — keeps test cases readable
function createNodeCode(/* parameterize the varying parts */): string {
  return `
import type { INodeType, INodeTypeDescription } from 'n8n-workflow';

export class TestNode implements INodeType {
  description: INodeTypeDescription = {
    displayName: 'Test Node',
    name: 'testNode',
    group: ['input'],
    version: 1,
    description: 'A test node',
    defaults: { name: 'Test Node' },
    inputs: [],
    outputs: [],
    properties: [],
  };
}`;
}

ruleTester.run('rule-name', YourRuleNameRule, {
  valid: [
    { name: 'class that does not implement INodeType', code: '...' },
    { name: 'node with correct pattern', code: createNodeCode(/* correct */) },
  ],
  invalid: [
    {
      name: 'descriptive case name',
      code: createNodeCode(/* incorrect */),
      errors: [{ messageId: 'messageId', data: { /* expected template vars */ } }],
      output: createNodeCode(/* expected after fix */),  // or `output: null` if no fix
    },
  ],
});

Test guidelines:

  • Always test that non-INodeType classes are skipped (valid case)
  • Test both the error message and the fixed output for fixable rules
  • For rules with options, test each option combination
  • For rules using filesystem, mock with vi.mock('../utils/file-utils.js')
  • For suggestion-only rules, use errors: [{ messageId, suggestions: [...] }]

Step 4: Register the Rule

4a. Add to src/rules/index.ts

import { YourRuleNameRule } from './rule-name.js';

// Add to the rules object:
export const rules = {
  // ... existing rules
  'rule-name': YourRuleNameRule,
} satisfies Record<string, AnyRuleModule>;

4b. Add to src/plugin.ts configs

Add to both config objects (unless the rule depends on n8n cloud features):

'@n8n/community-nodes/rule-name': 'error',  // or 'warn'
  • Use error for rules that catch bugs or required patterns
  • Use warn for style/convention rules (like options-sorted-alphabetically)
  • If the rule uses no-restricted-globals or no-restricted-imports patterns, only add to recommended (not recommendedWithoutN8nCloudSupport)

Step 5: Write Documentation

Create docs/rules/<rule-name>.md:

# Description of what the rule does (`@n8n/community-nodes/rule-name`)

<!-- end auto-generated rule header -->

## Rule Details

Explain why this rule exists and what problem it prevents.

## Examples

### Incorrect

\`\`\`typescript
// code that triggers the rule
\`\`\`

### Correct

\`\`\`typescript
// code that passes the rule
\`\`\`

The header above <!-- end auto-generated rule header --> will be regenerated by pnpm build:docs. Write a reasonable first version — it gets overwritten.

Step 6: Verify

Run from packages/@n8n/eslint-plugin-community-nodes/:

pushd packages/@n8n/eslint-plugin-community-nodes
pnpm test <rule-name>.test.ts   # tests pass
pnpm typecheck                   # types are clean
pnpm build                       # compiles
pnpm build:docs                  # regenerates doc headers and README table
pnpm lint:docs                   # docs match schema
popd

Checklist

  • Rule file: src/rules/<rule-name>.ts
  • Test file: src/rules/<rule-name>.test.ts
  • Registered in src/rules/index.ts
  • Added to configs in src/plugin.ts
  • Doc file: docs/rules/<rule-name>.md
  • README table updated via pnpm build:docs
  • All verification commands pass

版本历史

  • c31d0e5 当前 2026-08-20 19:07

同 Skill 集合

.agents/skills/community-pr-readiness-check/SKILL.md
.agents/skills/content-design/SKILL.md
.agents/skills/conventions/SKILL.md
.agents/skills/create-agent-builder-eval/SKILL.md
.agents/skills/create-instance-ai-eval/SKILL.md
.agents/skills/create-issue/SKILL.md
.agents/skills/create-pr/SKILL.md
.agents/skills/create-skill/SKILL.md
.agents/skills/db-migrations/SKILL.md
.agents/skills/design-system/SKILL.md
.agents/skills/experiments/SKILL.md
.agents/skills/gh-stack/SKILL.md
.agents/skills/human-like-code-review/SKILL.md
.agents/skills/linear-issue/SKILL.md
.agents/skills/loom-transcript/SKILL.md
.agents/skills/nathan/SKILL.md
.agents/skills/node-add-oauth/SKILL.md
.agents/skills/protect-endpoints/SKILL.md
.agents/skills/public-api/SKILL.md
.agents/skills/reproduce-bug/SKILL.md
.agents/skills/spec-driven-development/SKILL.md
.agents/skills/telemetry/SKILL.md
.agents/skills/ui-design/SKILL.md
.claude/plugins/n8n/skills/setup-mcps/SKILL.md
.opencode/skills/setup-mcps/SKILL.md
packages/@n8n/cli/skills/n8n-cli/SKILL.md
packages/@n8n/instance-ai/skills/agent-builder/SKILL.md
packages/@n8n/instance-ai/skills/config-evals/SKILL.md
packages/@n8n/instance-ai/skills/credential-recipe-research/SKILL.md
packages/@n8n/instance-ai/skills/credential-setup-with-computer-use/SKILL.md
packages/@n8n/instance-ai/skills/debugging-executions/SKILL.md
packages/@n8n/instance-ai/skills/instance-awareness/SKILL.md
packages/@n8n/instance-ai/skills/n8n-docs-assistant/SKILL.md
packages/@n8n/instance-ai/skills/planned-task-runtime/SKILL.md
packages/@n8n/instance-ai/skills/planning/SKILL.md
packages/@n8n/instance-ai/skills/post-build-flow/SKILL.md
packages/@n8n/instance-ai/skills/data-table-manager/SKILL.md
packages/@n8n/instance-ai/skills/intent-recognition/SKILL.md
packages/@n8n/instance-ai/skills/model-selection/SKILL.md
packages/@n8n/instance-ai/skills/one-off-operations/SKILL.md
packages/@n8n/instance-ai/skills/progressive-building/SKILL.md
packages/@n8n/instance-ai/skills/workflow-builder/SKILL.md

元信息

文件数
0
版本
fe0fad5
Hash
7efe4e55
收录时间
2026-08-20 19:07

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-23 15:21
浙ICP备14020137号-1