Socket
Socket
Sign inDemoInstall

eslint-docgen

Package Overview
Dependencies
100
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.5.1 to 0.6.0

Changelog.md

2

package.json
{
"name": "eslint-docgen",
"version": "0.5.1",
"version": "0.6.0",
"description": "Automatically generate ESLint plugin documentation from rule metadata and test cases.",

@@ -5,0 +5,0 @@ "repository": {

@@ -5,2 +5,9 @@ 'use strict';

const path = require( 'upath' );
// Mapping from extension to language name for markdown
// Default language is 'js'
const languageFromExtension = {
'.html': 'html',
'.ts': 'ts',
'.vue': 'vue'
};

@@ -64,13 +71,10 @@ /**

/**
*
* @param {string|Object} test
* @return {string|undefined} The base file name, or undefined if not set
* @param {string|Object} test Test case
* @return {string|null} The base file name, or null if not set
*/
function getFilename( test ) {
if ( typeof test === 'string' || test.filename === undefined ) {
// Either the test is just a code snippet, or its an object but with
// no file name set
return undefined;
// Either the test is just a code snippet, or no file name is set
return null;
}
// We don't need the full file path, just the last bit with the name and extension
return path.basename( test.filename );

@@ -116,10 +120,2 @@ }

testList.forEach( function ( test, i ) {
if ( !config.excludeExamplesByDefault && test.noDoc ) {
messages.push( {
type: 'warn',
text: '`noDoc: true` is deprecated. Use `docgen: false` instead.'
} );
return;
}
const docgen = test.docgen === undefined ?

@@ -133,20 +129,34 @@ !config.excludeExamplesByDefault :

let optionsAndSettings;
// Only include the filename if it should be shown
// Don't create an object if there are no options or settings and the file name is not
// set, so that those examples are sorted to the top of the docs
if (
test.options || test.settings ||
( config.showFilenames && getFilename( test ) )
) {
optionsAndSettings = {
options: test.options,
settings: test.settings
};
if ( config.showFilenames ) {
optionsAndSettings.filename = getFilename( test );
const filename = getFilename( test );
let lang = 'js';
// Switch to Vue if we are showing file names and its a Vue file.
// optionsAndSettings.filename is only set if it should be shown
// TODO should we add other languages too?
if ( filename ) {
const ext = path.extname( filename );
if ( ext in languageFromExtension ) {
lang = languageFromExtension[ ext ];
}
}
const hash = optionsAndSettings ? JSON.stringify( optionsAndSettings ) : '';
// Keys are in reverse sort order, e.g. examples with options
// are shown before examples with settings
const optionsAndSettings = {
// Always separate tests by language for syntax highlighting
lang: lang,
settings: test.settings,
options: test.options,
// Only group by filename if filenames are shown
filename: config.showFilenames && filename
};
const hashObject = {};
// Ensure examples without a specific key are shown first
Object.keys( optionsAndSettings ).forEach( ( key ) => {
hashObject[ key ] = optionsAndSettings[ key ] ?
[ '1', optionsAndSettings[ key ] ] :
[ '0', optionsAndSettings[ key ] ];
} );
const hash = JSON.stringify( hashObject );
codeSet[ hash ] = codeSet[ hash ] || {};

@@ -195,3 +205,4 @@

}
if ( multiLine || previousMultiLine ) {
// Put linebreaks around multi-line examples
if ( testsByOptions[ hash ].tests.length && ( multiLine || previousMultiLine ) ) {
example = '\n' + example;

@@ -222,2 +233,3 @@ }

const optionsAndSettings = section.optionsAndSettings;
const lang = optionsAndSettings && optionsAndSettings.lang;
const options = optionsAndSettings && optionsAndSettings.options;

@@ -227,3 +239,3 @@ const settings = optionsAndSettings && optionsAndSettings.settings;

let examples = '```js\n';
let examples = '```' + lang + '\n';
if ( config.showConfigComments ) {

@@ -230,0 +242,0 @@ examples += comments[ i ] + '\n';

@@ -6,11 +6,4 @@ 'use strict';

const ESLintRuleTester = require( packagePath( 'node_modules/eslint' ) ).RuleTester;
const docMode = !!process.env.DOCGEN || process.argv.includes( '--doc' );
const inDocMode = !!process.env.DOCGEN;
if ( process.argv.includes( '--doc' ) ) {
const formatter = require( './formatter' );
console.log(
formatter.warn( '--doc is deprecated, use the DOCGEN=1 environment variable instead.' )
);
}
/**

@@ -21,3 +14,3 @@ * Extends ESLint's RuleTester to also build documentation

run( name, rule, tests ) {
if ( docMode ) {
if ( inDocMode ) {
RuleTester.it( name, ( done ) => {

@@ -28,13 +21,9 @@ const writeDocsFromTests = require( './write-docs-from-tests' );

} else {
// Filter out invalid property "noDoc"
// Filter out invalid property "docgen"
// (used in documentation building mode).
tests.valid.forEach( ( test ) => {
delete test.docgen;
// Deprecated
delete test.noDoc;
} );
tests.invalid.forEach( ( test ) => {
delete test.docgen;
// Deprecated
delete test.noDoc;
} );

@@ -41,0 +30,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc