Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-doc-generator

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-doc-generator - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

13

dist/lib/rule-doc-notices.js
import { END_RULE_HEADER_MARKER } from './comment-markers.js';
import { EMOJI_DEPRECATED, EMOJI_FIXABLE, EMOJI_HAS_SUGGESTIONS, EMOJI_REQUIRES_TYPE_CHECKING, EMOJI_CONFIG_FROM_SEVERITY, EMOJI_OPTIONS, } from './emojis.js';
import { findConfigEmoji, getConfigsForRule } from './plugin-configs.js';
import { SEVERITY_TYPE, NOTICE_TYPE, } from './types.js';
import { SEVERITY_TYPE, NOTICE_TYPE, RULE_SOURCE, } from './types.js';
import { RULE_TYPE_MESSAGES_NOTICES } from './rule-type.js';

@@ -79,5 +79,9 @@ import { hasOptions } from './rule-options.js';

// Deprecated notice has optional "replaced by" rules list.
[NOTICE_TYPE.DEPRECATED]: ({ replacedBy, pluginPrefix, pathPlugin, pathRuleDoc, ruleName, urlRuleDoc, }) => {
const urlCurrentPage = getUrlToRule(ruleName, pluginPrefix, pathPlugin, pathRuleDoc, pathPlugin, urlRuleDoc);
const replacementRuleList = (replacedBy ?? []).map((replacementRuleName) => getLinkToRule(replacementRuleName, pluginPrefix, pathPlugin, pathRuleDoc, urlCurrentPage, true, true, urlRuleDoc));
[NOTICE_TYPE.DEPRECATED]: ({ replacedBy, plugin, pluginPrefix, pathPlugin, pathRuleDoc, ruleName, urlRuleDoc, }) => {
const urlCurrentPage = getUrlToRule(ruleName, RULE_SOURCE.self, pluginPrefix, pathPlugin, pathRuleDoc, pathPlugin, urlRuleDoc);
/* istanbul ignore next -- this shouldn't happen */
if (!urlCurrentPage) {
throw new Error('Missing URL to our own rule');
}
const replacementRuleList = (replacedBy ?? []).map((replacementRuleName) => getLinkToRule(replacementRuleName, plugin, pluginPrefix, pathPlugin, pathRuleDoc, urlCurrentPage, true, true, urlRuleDoc));
return `${EMOJI_DEPRECATED} This rule is deprecated.${replacedBy && replacedBy.length > 0

@@ -189,2 +193,3 @@ ? ` It was replaced by ${String(replacementRuleList)}.`

replacedBy: rule.meta?.replacedBy,
plugin,
pluginPrefix,

@@ -191,0 +196,0 @@ pathPlugin,

@@ -0,1 +1,2 @@

import { Plugin, RULE_SOURCE } from './types.js';
export declare function replaceRulePlaceholder(pathOrUrl: string, ruleName: string): string;

@@ -6,6 +7,6 @@ /**

*/
export declare function getUrlToRule(ruleName: string, pluginPrefix: string, pathPlugin: string, pathRuleDoc: string, urlCurrentPage: string, urlRuleDoc?: string): string;
export declare function getUrlToRule(ruleName: string, ruleSource: RULE_SOURCE, pluginPrefix: string, pathPlugin: string, pathRuleDoc: string, urlCurrentPage: string, urlRuleDoc?: string): string | undefined;
/**
* Get the markdown link (title and URL) to the rule's documentation.
*/
export declare function getLinkToRule(ruleName: string, pluginPrefix: string, pathPlugin: string, pathRuleDoc: string, urlCurrentPage: string, includeBackticks: boolean, includePrefix: boolean, urlRuleDoc?: string): string;
export declare function getLinkToRule(ruleName: string, plugin: Plugin, pluginPrefix: string, pathPlugin: string, pathRuleDoc: string, urlCurrentPage: string, includeBackticks: boolean, includePrefix: boolean, urlRuleDoc?: string): string;
import { countOccurrencesInString } from './string.js';
import { join, sep, relative } from 'node:path';
import { RULE_SOURCE } from './types.js';
export function replaceRulePlaceholder(pathOrUrl, ruleName) {

@@ -27,3 +28,13 @@ return pathOrUrl.replace(/\{name\}/gu, ruleName);

*/
export function getUrlToRule(ruleName, pluginPrefix, pathPlugin, pathRuleDoc, urlCurrentPage, urlRuleDoc) {
export function getUrlToRule(ruleName, ruleSource, pluginPrefix, pathPlugin, pathRuleDoc, urlCurrentPage, urlRuleDoc) {
switch (ruleSource) {
case RULE_SOURCE.eslintCore:
return `https://eslint.org/docs/latest/rules/${ruleName}`;
case RULE_SOURCE.thirdPartyPlugin:
// We don't know the documentation URL to third-party plugins.
return undefined; // eslint-disable-line unicorn/no-useless-undefined
default:
// Fallthrough to remaining logic in function.
break;
}
const nestingDepthOfCurrentPage = countOccurrencesInString(relative(pathPlugin, urlCurrentPage), sep);

@@ -43,11 +54,28 @@ const relativePathPluginRoot = goUpLevel(nestingDepthOfCurrentPage);

*/
export function getLinkToRule(ruleName, pluginPrefix, pathPlugin, pathRuleDoc, urlCurrentPage, includeBackticks, includePrefix, urlRuleDoc) {
const ruleNameWithPluginPrefix = ruleName.startsWith(`${pluginPrefix}/`)
? ruleName
: `${pluginPrefix}/${ruleName}`;
export function getLinkToRule(ruleName, plugin, pluginPrefix, pathPlugin, pathRuleDoc, urlCurrentPage, includeBackticks, includePrefix, urlRuleDoc) {
const ruleNameWithoutPluginPrefix = ruleName.startsWith(`${pluginPrefix}/`)
? ruleName.slice(pluginPrefix.length + 1)
: ruleName;
const urlToRule = getUrlToRule(ruleName, pluginPrefix, pathPlugin, pathRuleDoc, urlCurrentPage, urlRuleDoc);
return `[${includeBackticks ? '`' : ''}${includePrefix ? ruleNameWithPluginPrefix : ruleNameWithoutPluginPrefix}${includeBackticks ? '`' : ''}](${urlToRule})`;
// Determine what plugin this rule comes from.
let ruleSource;
if (plugin.rules?.[ruleNameWithoutPluginPrefix]) {
ruleSource = RULE_SOURCE.self;
}
else if (ruleName.includes('/')) {
// Assume a slash is for the plugin prefix (ESLint core doesn't have any nested rules).
ruleSource = RULE_SOURCE.thirdPartyPlugin;
}
else {
ruleSource = RULE_SOURCE.eslintCore;
}
const ruleNameWithPluginPrefix = ruleName.startsWith(`${pluginPrefix}/`)
? ruleName
: ruleSource === RULE_SOURCE.self
? `${pluginPrefix}/${ruleName}`
: undefined;
const urlToRule = getUrlToRule(ruleName, ruleSource, pluginPrefix, pathPlugin, pathRuleDoc, urlCurrentPage, urlRuleDoc);
const ruleNameToDisplay = `${includeBackticks ? '`' : ''}${includePrefix && ruleNameWithPluginPrefix
? ruleNameWithPluginPrefix
: ruleNameWithoutPluginPrefix}${includeBackticks ? '`' : ''}`;
return urlToRule ? `[${ruleNameToDisplay}](${urlToRule})` : ruleNameToDisplay;
}

@@ -44,3 +44,3 @@ import { BEGIN_RULE_LIST_MARKER, END_RULE_LIST_MARKER, } from './comment-markers.js';

}
function buildRuleRow(ruleName, rule, columnsEnabled, configsToRules, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc) {
function buildRuleRow(ruleName, rule, columnsEnabled, configsToRules, plugin, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc) {
const columns = {

@@ -59,3 +59,3 @@ // Alphabetical order.

[COLUMN_TYPE.NAME]() {
return getLinkToRule(ruleName, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, false, false, urlRuleDoc);
return getLinkToRule(ruleName, plugin, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, false, false, urlRuleDoc);
},

@@ -80,3 +80,3 @@ [COLUMN_TYPE.OPTIONS]: hasOptions(rule.meta?.schema) ? EMOJI_OPTIONS : '',

}
function generateRulesListMarkdown(ruleNamesAndRules, columns, configsToRules, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc) {
function generateRulesListMarkdown(ruleNamesAndRules, columns, configsToRules, plugin, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc) {
const listHeaderRow = Object.entries(columns).flatMap(([columnType, enabled]) => {

@@ -95,7 +95,7 @@ if (!enabled) {

listHeaderRow,
...ruleNamesAndRules.map(([name, rule]) => buildRuleRow(name, rule, columns, configsToRules, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc)),
...ruleNamesAndRules.map(([name, rule]) => buildRuleRow(name, rule, columns, configsToRules, plugin, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc)),
], { align: 'l' } // Left-align headers.
);
}
function generateRuleListMarkdownForRulesAndHeaders(rulesAndHeaders, headerLevel, columns, configsToRules, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc) {
function generateRuleListMarkdownForRulesAndHeaders(rulesAndHeaders, headerLevel, columns, configsToRules, plugin, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc) {
const parts = [];

@@ -106,3 +106,3 @@ for (const { title, rules } of rulesAndHeaders) {

}
parts.push(generateRulesListMarkdown(rules, columns, configsToRules, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc));
parts.push(generateRulesListMarkdown(rules, columns, configsToRules, plugin, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc));
}

@@ -259,5 +259,5 @@ return parts.join('\n\n');

// New rule list.
const list = generateRuleListMarkdownForRulesAndHeaders(rulesAndHeaders, ruleListSplitHeaderLevel, columns, configsToRules, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc);
const list = generateRuleListMarkdownForRulesAndHeaders(rulesAndHeaders, ruleListSplitHeaderLevel, columns, configsToRules, plugin, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc);
const newContent = `${legend ? `${legend}\n\n` : ''}${list}`;
return `${preList}${BEGIN_RULE_LIST_MARKER}\n\n${newContent}\n\n${END_RULE_LIST_MARKER}${postList}`;
}

@@ -8,2 +8,10 @@ import type { RuleDocTitleFormat } from './rule-doc-title-format.js';

export type Plugin = TSESLint.Linter.Plugin;
/**
* Where a rule comes from (where it's defined).
*/
export declare enum RULE_SOURCE {
'self' = "self",
'eslintCore' = "eslintCore",
'thirdPartyPlugin' = "thirdPartyPlugin"
}
export declare const SEVERITY_ERROR: Set<TSESLint.Linter.RuleLevel>;

@@ -10,0 +18,0 @@ export declare const SEVERITY_WARN: Set<TSESLint.Linter.RuleLevel>;

// Custom types.
/**
* Where a rule comes from (where it's defined).
*/
export var RULE_SOURCE;
(function (RULE_SOURCE) {
RULE_SOURCE["self"] = "self";
RULE_SOURCE["eslintCore"] = "eslintCore";
RULE_SOURCE["thirdPartyPlugin"] = "thirdPartyPlugin";
})(RULE_SOURCE || (RULE_SOURCE = {}));
export const SEVERITY_ERROR = new Set([2, 'error']);

@@ -3,0 +12,0 @@ export const SEVERITY_WARN = new Set([1, 'warn']);

{
"name": "eslint-doc-generator",
"version": "1.2.0",
"version": "1.2.1",
"description": "Automatic documentation generator for ESLint plugins and rules.",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc