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 0.8.0 to 0.8.1

20

dist/lib/generator.js
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { join, resolve, relative } from 'node:path';
import { join, relative, resolve } from 'node:path';
import { getAllNamedOptions, hasOptions } from './rule-options.js';
import { loadPlugin, getPluginPrefix, getPluginRoot } from './package-json.js';
import { loadPlugin, getPluginPrefix, getPluginRoot, getPathWithExactFileNameCasing, } from './package-json.js';
import { updateRulesList } from './rule-list.js';

@@ -42,6 +42,2 @@ import { generateRuleHeaderLines } from './rule-notices.js';

const configsToRules = await resolveConfigsToRules(plugin);
const pathTo = {
readme: resolve(path, 'README.md'),
docs: resolve(path, 'docs'),
};
if (!plugin.rules) {

@@ -82,3 +78,3 @@ throw new Error('Could not find exported `rules` object in ESLint plugin.');

for (const { name, description, schema } of details) {
const pathToDoc = join(pathTo.docs, 'rules', `${name}.md`);
const pathToDoc = join(resolve(path, 'docs'), 'rules', `${name}.md`);
if (!existsSync(pathToDoc)) {

@@ -107,8 +103,10 @@ throw new Error(`Could not find rule doc: ${relative(getPluginRoot(path), pathToDoc)}`);

}
if (!existsSync(pathTo.readme)) {
throw new Error(`Could not find README: ${relative(getPluginRoot(path), pathTo.readme)}`);
// Find the README.
const pathToReadme = getPathWithExactFileNameCasing(path, 'README.md');
if (!pathToReadme || !existsSync(pathToReadme)) {
throw new Error('Could not find README.md in ESLint plugin root.');
}
// Update the rules list in the README.
const readme = await updateRulesList(details, readFileSync(pathTo.readme, 'utf8'), plugin, configsToRules, pluginPrefix, pathTo.readme, options?.ignoreConfig, options?.urlConfigs);
writeFileSync(pathTo.readme, readme, 'utf8');
const readme = await updateRulesList(details, readFileSync(pathToReadme, 'utf8'), plugin, configsToRules, pluginPrefix, pathToReadme, path, options?.ignoreConfig, options?.urlConfigs);
writeFileSync(pathToReadme, readme, 'utf8');
}

@@ -5,1 +5,5 @@ import type { Plugin } from './types.js';

export declare function getPluginPrefix(path: string): string;
/**
* Resolve the path to a file but with the exact filename-casing present on disk.
*/
export declare function getPathWithExactFileNameCasing(dir: string, fileNameToSearch: string): string | undefined;

@@ -1,3 +0,3 @@

import { join } from 'node:path';
import { existsSync, readFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { existsSync, readFileSync, readdirSync } from 'node:fs';
import { importAbs } from './import.js';

@@ -33,1 +33,14 @@ export function getPluginRoot(path) {

}
/**
* Resolve the path to a file but with the exact filename-casing present on disk.
*/
export function getPathWithExactFileNameCasing(dir, fileNameToSearch) {
const filenames = readdirSync(dir, { withFileTypes: true });
for (const dirent of filenames) {
if (dirent.isFile() &&
dirent.name.toLowerCase() === fileNameToSearch.toLowerCase()) {
return resolve(dir, dirent.name);
}
}
return undefined; // eslint-disable-line unicorn/no-useless-undefined
}
import type { Plugin, RuleDetails, ConfigsToRules } from './types.js';
export declare function updateRulesList(details: RuleDetails[], markdown: string, plugin: Plugin, configsToRules: ConfigsToRules, pluginPrefix: string, pathToReadme: string, ignoreConfig?: string[], urlConfigs?: string): Promise<string>;
export declare function updateRulesList(details: RuleDetails[], markdown: string, plugin: Plugin, configsToRules: ConfigsToRules, pluginPrefix: string, pathToReadme: string, pathToPlugin: string, ignoreConfig?: string[], urlConfigs?: string): Promise<string>;

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

import { findSectionHeader, format } from './markdown.js';
import { getPluginRoot } from './package-json.js';
import { generateLegend } from './legend.js';
import { relative } from 'node:path';
function getConfigurationColumnValueForRule(rule, configsToRules, pluginPrefix, ignoreConfig) {

@@ -72,3 +74,3 @@ const badges = [];

}
export async function updateRulesList(details, markdown, plugin, configsToRules, pluginPrefix, pathToReadme, ignoreConfig, urlConfigs) {
export async function updateRulesList(details, markdown, plugin, configsToRules, pluginPrefix, pathToReadme, pathToPlugin, ignoreConfig, urlConfigs) {
let listStartIndex = markdown.indexOf(BEGIN_RULE_LIST_MARKER);

@@ -94,3 +96,3 @@ let listEndIndex = markdown.indexOf(END_RULE_LIST_MARKER);

if (listStartIndex === -1 || listEndIndex === -1) {
throw new Error(`README.md is missing rules list markers: ${BEGIN_RULE_LIST_MARKER}${END_RULE_LIST_MARKER}`);
throw new Error(`${relative(getPluginRoot(pathToPlugin), pathToReadme)} is missing rules list markers: ${BEGIN_RULE_LIST_MARKER}${END_RULE_LIST_MARKER}`);
}

@@ -97,0 +99,0 @@ const preList = markdown.slice(0, Math.max(0, listStartIndex));

{
"name": "eslint-doc-generator",
"version": "0.8.0",
"version": "0.8.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