remark-lint-directive-unique-attribute-name

raw JSON →
1.0.1 verified Fri May 01 auth: no javascript

remark-lint rule that warns when directive attribute names are reused within the same directive. Version 1.0.1 is current stable, part of the remark-lint ecosystem. It checks that each attribute name in a directive (like `:planet[Venus]{aphelion=0.728213 perihelion=0.718440}`) appears only once. Unlike generic linting, this targets the unique syntax of directives, which are custom containers in markdown. Requires remark-lint and remark-directive to function. Ships TypeScript types. Released under MIT license.

error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/remark-lint-directive-unique-attribute-name/index.js from /path/to/file.js not supported.
cause Using require() on an ESM-only package.
fix
Change to import statement: import remarkLintDirectiveUniqueAttributeName from 'remark-lint-directive-unique-attribute-name'
error Unexpected attribute name with equal text, expected unique attribute names
cause Duplicate attribute names in the same directive.
fix
Remove or rename duplicate attributes so each name appears only once.
gotcha Package requires remark-directive to be loaded before remark-lint-directive-unique-attribute-name, otherwise it does nothing.
fix Ensure unified pipeline includes .use(remarkDirective) before this rule.
gotcha This rule only checks attributes within the same directive node; it does not check uniqueness across multiple directives or across other elements.
fix Understand scope: each directive is validated independently.
gotcha ESM-only: Node.js 16+ required; import, not require.
fix Use ES import syntax or upgrade Node.js.
npm install remark-lint-directive-unique-attribute-name
yarn add remark-lint-directive-unique-attribute-name
pnpm add remark-lint-directive-unique-attribute-name

Shows how to set up the rule with required plugins and check for duplicate attribute names in directives.

import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkDirective from 'remark-directive';
import remarkLint from 'remark-lint';
import remarkLintDirectiveUniqueAttributeName from 'remark-lint-directive-unique-attribute-name';
import remarkStringify from 'remark-stringify';
import { reporter } from 'vfile-reporter';

const file = await unified()
  .use(remarkParse)
  .use(remarkDirective)
  .use(remarkLint)
  .use(remarkLintDirectiveUniqueAttributeName)
  .use(remarkStringify)
  .process(':planet[Venus]{aphelion=0.728213 perihelion=0.718440 symbol=♀︎}');

console.error(reporter(file)); // no warnings

const file2 = await unified()
  .use(remarkParse)
  .use(remarkDirective)
  .use(remarkLint)
  .use(remarkLintDirectiveUniqueAttributeName)
  .use(remarkStringify)
  .process(':planet[Venus]{aphelion=0.728213 aphelion=0.718440}');

console.error(reporter(file2)); // warns about duplicate 'aphelion'