eslint-plugin-jsdoc 40.1.1 → 40.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +191 -10
- package/dist/bin/generateRule.js +2 -2
- package/dist/bin/generateRule.js.map +1 -1
- package/dist/generateRule.js +2 -2
- package/dist/generateRule.js.map +1 -1
- package/dist/iterateJsdoc.js +33 -12
- package/dist/iterateJsdoc.js.map +1 -1
- package/dist/rules/checkTagNames.js +72 -3
- package/dist/rules/checkTagNames.js.map +1 -1
- package/dist/rules/matchName.js +2 -2
- package/dist/rules/matchName.js.map +1 -1
- package/dist/rules/multilineBlocks.js +1 -1
- package/dist/rules/multilineBlocks.js.map +1 -1
- package/dist/rules/noMultiAsterisks.js +1 -1
- package/dist/rules/noMultiAsterisks.js.map +1 -1
- package/dist/rules/sortTags.js +1 -1
- package/dist/rules/sortTags.js.map +1 -1
- package/dist/rules/tagLines.js +7 -3
- package/dist/rules/tagLines.js.map +1 -1
- package/dist/rules/textEscaping.js +1 -1
- package/dist/rules/textEscaping.js.map +1 -1
- package/dist/rules/validTypes.js +1 -1
- package/dist/rules/validTypes.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4486,6 +4486,12 @@ The format is as follows:
|
|
|
4486
4486
|
}
|
|
4487
4487
|
```
|
|
4488
4488
|
|
|
4489
|
+
<a name="user-content-eslint-plugin-jsdoc-rules-check-tag-names-options-6-enablefixer-2"></a>
|
|
4490
|
+
<a name="eslint-plugin-jsdoc-rules-check-tag-names-options-6-enablefixer-2"></a>
|
|
4491
|
+
##### <code>enableFixer</code>
|
|
4492
|
+
|
|
4493
|
+
Set to `false` to disable auto-removal of types that are redundant with the [`typed` option](#user-content-typed).
|
|
4494
|
+
|
|
4489
4495
|
<a name="user-content-eslint-plugin-jsdoc-rules-check-tag-names-jsxtags"></a>
|
|
4490
4496
|
<a name="eslint-plugin-jsdoc-rules-check-tag-names-jsxtags"></a>
|
|
4491
4497
|
#### <code>jsxTags</code>
|
|
@@ -4501,6 +4507,64 @@ jsxRuntime
|
|
|
4501
4507
|
|
|
4502
4508
|
For more information, see the [babel documentation](https://babeljs.io/docs/en/babel-plugin-transform-react-jsx).
|
|
4503
4509
|
|
|
4510
|
+
<a name="user-content-eslint-plugin-jsdoc-rules-check-tag-names-typed"></a>
|
|
4511
|
+
<a name="eslint-plugin-jsdoc-rules-check-tag-names-typed"></a>
|
|
4512
|
+
#### <code>typed</code>
|
|
4513
|
+
|
|
4514
|
+
If this is set to `true`, additionally checks for tag names that are redundant when using a type checker such as TypeScript.
|
|
4515
|
+
|
|
4516
|
+
These tags are always unnecessary when using TypeScript or similar:
|
|
4517
|
+
|
|
4518
|
+
```
|
|
4519
|
+
augments
|
|
4520
|
+
callback
|
|
4521
|
+
class
|
|
4522
|
+
enum
|
|
4523
|
+
implements
|
|
4524
|
+
private
|
|
4525
|
+
property
|
|
4526
|
+
protected
|
|
4527
|
+
public
|
|
4528
|
+
readonly
|
|
4529
|
+
this
|
|
4530
|
+
type
|
|
4531
|
+
typedef
|
|
4532
|
+
```
|
|
4533
|
+
|
|
4534
|
+
These tags are unnecessary except when inside a TypeScript `declare` context:
|
|
4535
|
+
|
|
4536
|
+
```
|
|
4537
|
+
abstract
|
|
4538
|
+
access
|
|
4539
|
+
class
|
|
4540
|
+
constant
|
|
4541
|
+
constructs
|
|
4542
|
+
default
|
|
4543
|
+
enum
|
|
4544
|
+
export
|
|
4545
|
+
exports
|
|
4546
|
+
function
|
|
4547
|
+
global
|
|
4548
|
+
inherits
|
|
4549
|
+
instance
|
|
4550
|
+
interface
|
|
4551
|
+
member
|
|
4552
|
+
memberof
|
|
4553
|
+
memberOf
|
|
4554
|
+
method
|
|
4555
|
+
mixes
|
|
4556
|
+
mixin
|
|
4557
|
+
module
|
|
4558
|
+
name
|
|
4559
|
+
namespace
|
|
4560
|
+
override
|
|
4561
|
+
property
|
|
4562
|
+
requires
|
|
4563
|
+
static
|
|
4564
|
+
this
|
|
4565
|
+
```
|
|
4566
|
+
|
|
4567
|
+
Additionally, for `@param` and `@return` tags, the rule will flag unnecessary type descriptions (e.g. `@param {string}`).
|
|
4504
4568
|
|
|
4505
4569
|
|||
|
|
4506
4570
|
|---|---|
|
|
@@ -4513,6 +4577,72 @@ For more information, see the [babel documentation](https://babeljs.io/docs/en/b
|
|
|
4513
4577
|
The following patterns are considered problems:
|
|
4514
4578
|
|
|
4515
4579
|
````js
|
|
4580
|
+
/** @type {string} */let a;
|
|
4581
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
4582
|
+
// Message: '@type' is redundant when using a type system.
|
|
4583
|
+
|
|
4584
|
+
/** @type {string} */let a;
|
|
4585
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"enableFixer":false,"typed":true}]
|
|
4586
|
+
// Message: '@type' is redundant when using a type system.
|
|
4587
|
+
|
|
4588
|
+
/** @type {string} */ let a;
|
|
4589
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
4590
|
+
// Message: '@type' is redundant when using a type system.
|
|
4591
|
+
|
|
4592
|
+
/** @type {string} */
|
|
4593
|
+
let a;
|
|
4594
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
4595
|
+
// Message: '@type' is redundant when using a type system.
|
|
4596
|
+
|
|
4597
|
+
/** @type {string} */
|
|
4598
|
+
let a;
|
|
4599
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
4600
|
+
// Message: '@type' is redundant when using a type system.
|
|
4601
|
+
|
|
4602
|
+
/** @type {string} - extra info */
|
|
4603
|
+
let a;
|
|
4604
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
4605
|
+
// Message: '@type' is redundant when using a type system.
|
|
4606
|
+
|
|
4607
|
+
/**
|
|
4608
|
+
* Existing comment.
|
|
4609
|
+
* @type {string}
|
|
4610
|
+
*/
|
|
4611
|
+
let a;
|
|
4612
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
4613
|
+
// Message: '@type' is redundant when using a type system.
|
|
4614
|
+
|
|
4615
|
+
/** @abstract */
|
|
4616
|
+
let a;
|
|
4617
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
4618
|
+
// Message: '@abstract' is redundant outside of ambient (`declare`/`.d.ts`) contexts when using a type system.
|
|
4619
|
+
|
|
4620
|
+
/** @abstract */
|
|
4621
|
+
let a;
|
|
4622
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"enableFixer":false,"typed":true}]
|
|
4623
|
+
// Message: '@abstract' is redundant outside of ambient (`declare`/`.d.ts`) contexts when using a type system.
|
|
4624
|
+
|
|
4625
|
+
const a = {
|
|
4626
|
+
/** @abstract */
|
|
4627
|
+
b: true,
|
|
4628
|
+
};
|
|
4629
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
4630
|
+
// Message: '@abstract' is redundant outside of ambient (`declare`/`.d.ts`) contexts when using a type system.
|
|
4631
|
+
|
|
4632
|
+
/** @template */
|
|
4633
|
+
let a;
|
|
4634
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
4635
|
+
// Message: '@template' without a name is redundant when using a type system.
|
|
4636
|
+
|
|
4637
|
+
/**
|
|
4638
|
+
* Prior description.
|
|
4639
|
+
*
|
|
4640
|
+
* @template
|
|
4641
|
+
*/
|
|
4642
|
+
let a;
|
|
4643
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
4644
|
+
// Message: '@template' without a name is redundant when using a type system.
|
|
4645
|
+
|
|
4516
4646
|
/** @typoo {string} */
|
|
4517
4647
|
let a;
|
|
4518
4648
|
// Message: Invalid JSDoc tag name "typoo".
|
|
@@ -4869,6 +4999,40 @@ function Test() {
|
|
|
4869
4999
|
The following patterns are not considered problems:
|
|
4870
5000
|
|
|
4871
5001
|
````js
|
|
5002
|
+
/** @default 0 */
|
|
5003
|
+
let a;
|
|
5004
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
5005
|
+
|
|
5006
|
+
/** @default 0 */
|
|
5007
|
+
declare let a;
|
|
5008
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
5009
|
+
|
|
5010
|
+
/** @abstract */
|
|
5011
|
+
let a;
|
|
5012
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
5013
|
+
|
|
5014
|
+
/** @abstract */
|
|
5015
|
+
declare let a;
|
|
5016
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
5017
|
+
|
|
5018
|
+
/** @abstract */
|
|
5019
|
+
{ declare let a; }
|
|
5020
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
5021
|
+
|
|
5022
|
+
function test() {
|
|
5023
|
+
/** @abstract */
|
|
5024
|
+
declare let a;
|
|
5025
|
+
}
|
|
5026
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
5027
|
+
|
|
5028
|
+
/** @template name */
|
|
5029
|
+
let a;
|
|
5030
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
5031
|
+
|
|
5032
|
+
/** @param param - takes information */
|
|
5033
|
+
function takesOne(param) {}
|
|
5034
|
+
// "jsdoc/check-tag-names": ["error"|"warn", {"typed":true}]
|
|
5035
|
+
|
|
4872
5036
|
/**
|
|
4873
5037
|
* @param foo
|
|
4874
5038
|
*/
|
|
@@ -5148,6 +5312,23 @@ export function transient<T>(target?: T): T {
|
|
|
5148
5312
|
* @internal
|
|
5149
5313
|
*/
|
|
5150
5314
|
// Settings: {"jsdoc":{"mode":"typescript"}}
|
|
5315
|
+
|
|
5316
|
+
interface WebTwain {
|
|
5317
|
+
/**
|
|
5318
|
+
* Converts the images specified by the indices to base64 synchronously.
|
|
5319
|
+
* @function WebTwain#ConvertToBase64
|
|
5320
|
+
* @returns {Base64Result}
|
|
5321
|
+
|
|
5322
|
+
ConvertToBase64(): Base64Result;
|
|
5323
|
+
*/
|
|
5324
|
+
|
|
5325
|
+
/**
|
|
5326
|
+
* Converts the images specified by the indices to base64 asynchronously.
|
|
5327
|
+
* @function WebTwain#ConvertToBase64
|
|
5328
|
+
* @returns {boolean}
|
|
5329
|
+
*/
|
|
5330
|
+
ConvertToBase64(): boolean;
|
|
5331
|
+
}
|
|
5151
5332
|
````
|
|
5152
5333
|
|
|
5153
5334
|
|
|
@@ -8537,12 +8718,12 @@ The following patterns are considered problems:
|
|
|
8537
8718
|
|
|
8538
8719
|
/**
|
|
8539
8720
|
* @someTag {aType} with Description */
|
|
8540
|
-
// "jsdoc/multiline-blocks": ["error"|"warn", {"
|
|
8721
|
+
// "jsdoc/multiline-blocks": ["error"|"warn", {"noFinalLineText":true}]
|
|
8541
8722
|
// Message: Should have no text on the final line (before the `*/`).
|
|
8542
8723
|
|
|
8543
8724
|
/**
|
|
8544
8725
|
* Description */
|
|
8545
|
-
// "jsdoc/multiline-blocks": ["error"|"warn", {"
|
|
8726
|
+
// "jsdoc/multiline-blocks": ["error"|"warn", {"noFinalLineText":true}]
|
|
8546
8727
|
// Message: Should have no text on the final line (before the `*/`).
|
|
8547
8728
|
````
|
|
8548
8729
|
|
|
@@ -8648,7 +8829,7 @@ The following patterns are not considered problems:
|
|
|
8648
8829
|
// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":false,"multilineTags":["oneTag"],"noMultilineBlocks":true}]
|
|
8649
8830
|
|
|
8650
8831
|
/** @someTag with Description */
|
|
8651
|
-
// "jsdoc/multiline-blocks": ["error"|"warn", {"
|
|
8832
|
+
// "jsdoc/multiline-blocks": ["error"|"warn", {"noFinalLineText":true}]
|
|
8652
8833
|
````
|
|
8653
8834
|
|
|
8654
8835
|
|
|
@@ -12620,8 +12801,8 @@ A value indicating whether getters should be checked. Defaults to `false`.
|
|
|
12620
12801
|
|
|
12621
12802
|
A value indicating whether setters should be checked. Defaults to `false`.
|
|
12622
12803
|
|
|
12623
|
-
<a name="user-content-eslint-plugin-jsdoc-rules-require-example-options-25-enablefixer-
|
|
12624
|
-
<a name="eslint-plugin-jsdoc-rules-require-example-options-25-enablefixer-
|
|
12804
|
+
<a name="user-content-eslint-plugin-jsdoc-rules-require-example-options-25-enablefixer-3"></a>
|
|
12805
|
+
<a name="eslint-plugin-jsdoc-rules-require-example-options-25-enablefixer-3"></a>
|
|
12625
12806
|
##### <code>enableFixer</code>
|
|
12626
12807
|
|
|
12627
12808
|
A boolean on whether to enable the fixer (which adds an empty `@example` block).
|
|
@@ -13559,8 +13740,8 @@ setters should be checked but only when there is no getter. This may be useful
|
|
|
13559
13740
|
if one only wishes documentation on one of the two accessors. Defaults to
|
|
13560
13741
|
`false`.
|
|
13561
13742
|
|
|
13562
|
-
<a name="user-content-eslint-plugin-jsdoc-rules-require-jsdoc-options-28-enablefixer-
|
|
13563
|
-
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-28-enablefixer-
|
|
13743
|
+
<a name="user-content-eslint-plugin-jsdoc-rules-require-jsdoc-options-28-enablefixer-4"></a>
|
|
13744
|
+
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-28-enablefixer-4"></a>
|
|
13564
13745
|
##### <code>enableFixer</code>
|
|
13565
13746
|
|
|
13566
13747
|
A boolean on whether to enable the fixer (which adds an empty jsdoc block).
|
|
@@ -16010,8 +16191,8 @@ function signature, it may appear that there is an actual property named
|
|
|
16010
16191
|
|
|
16011
16192
|
An options object accepts the following optional properties:
|
|
16012
16193
|
|
|
16013
|
-
<a name="user-content-eslint-plugin-jsdoc-rules-require-param-options-32-enablefixer-
|
|
16014
|
-
<a name="eslint-plugin-jsdoc-rules-require-param-options-32-enablefixer-
|
|
16194
|
+
<a name="user-content-eslint-plugin-jsdoc-rules-require-param-options-32-enablefixer-5"></a>
|
|
16195
|
+
<a name="eslint-plugin-jsdoc-rules-require-param-options-32-enablefixer-5"></a>
|
|
16015
16196
|
##### <code>enableFixer</code>
|
|
16016
16197
|
|
|
16017
16198
|
Whether to enable the fixer. Defaults to `true`.
|
|
@@ -23647,7 +23828,7 @@ function quux ( id, options ) {
|
|
|
23647
23828
|
function assign(employees) {
|
|
23648
23829
|
// ...
|
|
23649
23830
|
}
|
|
23650
|
-
// "jsdoc/valid-types": ["error"|"warn", {"allowEmptyNamepaths":true
|
|
23831
|
+
// "jsdoc/valid-types": ["error"|"warn", {"allowEmptyNamepaths":true}]
|
|
23651
23832
|
|
|
23652
23833
|
/**
|
|
23653
23834
|
* @param {typeof obj["level1"]["level2"]} foo
|
package/dist/bin/generateRule.js
CHANGED
|
@@ -45,7 +45,7 @@ export default iterateJsdoc(({
|
|
|
45
45
|
},
|
|
46
46
|
schema: [
|
|
47
47
|
{
|
|
48
|
-
|
|
48
|
+
additionalProperties: false,
|
|
49
49
|
properties: {
|
|
50
50
|
// Option properties here (or remove the object)
|
|
51
51
|
},
|
|
@@ -68,7 +68,7 @@ export default iterateJsdoc(({
|
|
|
68
68
|
\`,
|
|
69
69
|
errors: [
|
|
70
70
|
{
|
|
71
|
-
line:
|
|
71
|
+
line: 2,
|
|
72
72
|
message: '',
|
|
73
73
|
},
|
|
74
74
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRule.js","names":["_fs","require","_promises","_interopRequireDefault","_path","_camelcase","_openEditor","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","_interopRequireWildcard","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ruleName","options","process","argv","recommended","includes","console","error","test","ruleNamesPath","ruleNames","JSON","parse","fs","readFile","push","sort","writeFile","stringify","log","ruleTemplate","camelCasedRuleName","camelCase","rulePath","existsSync","ruleTestTemplate","ruleTestPath","ruleReadmeTemplate","ruleReadmePath","replaceInOrder","path","oldRegex","checkName","newLine","oldIsCamel","offsets","readme","replace","matchedLine","n1","offset","str","oldRule","oldRuleB","alreadyIncluded","itemIndex","findIndex","item","undefined","pop","length","slice","repeat","Promise","resolve","then","chdir","__dirname","open"],"sources":["../../src/bin/generateRule.js"],"sourcesContent":["/* eslint-disable no-console -- CLI */\n\n/**\n * @example\n *\n * ```shell\n * npm run create-rule my-new-rule -- --recommended\n * ```\n */\n\nimport {\n existsSync,\n} from 'fs';\nimport fs from 'fs/promises';\nimport {\n resolve,\n} from 'path';\nimport camelCase from 'camelcase';\nimport open from 'open-editor';\n\n// Todo: Would ideally have prompts, e.g., to ask for whether type was problem/layout, etc.\n\nconst [\n , , ruleName,\n ...options\n] = process.argv;\n\nconst recommended = options.includes('--recommended');\n\n(async () => {\n if (!ruleName) {\n console.error('Please supply a rule name');\n\n return;\n }\n\n if ((/[A-Z]/u).test(ruleName)) {\n console.error('Please ensure the rule has no capital letters');\n\n return;\n }\n\n const ruleNamesPath = './test/rules/ruleNames.json';\n const ruleNames = JSON.parse(await fs.readFile(\n ruleNamesPath, 'utf8',\n ));\n if (!ruleNames.includes(ruleName)) {\n ruleNames.push(ruleName);\n ruleNames.sort();\n }\n\n await fs.writeFile(ruleNamesPath, JSON.stringify(ruleNames, null, 2) + '\\n');\n console.log('ruleNames', ruleNames);\n\n const ruleTemplate = `import iterateJsdoc from '../iterateJsdoc';\n\nexport default iterateJsdoc(({\n context,\n utils,\n}) => {\n // Rule here\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: '',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-${ruleName}',\n },\n schema: [\n {\n additionalProperies: false,\n properties: {\n // Option properties here (or remove the object)\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n`;\n\n const camelCasedRuleName = camelCase(ruleName);\n\n const rulePath = `./src/rules/${camelCasedRuleName}.js`;\n\n if (!existsSync(rulePath)) {\n await fs.writeFile(rulePath, ruleTemplate);\n }\n\n const ruleTestTemplate = `export default {\n invalid: [\n {\n code: \\`\n \\`,\n errors: [\n {\n line: '',\n message: '',\n },\n ],\n },\n ],\n valid: [\n {\n code: \\`\n \\`,\n },\n ],\n};\n`;\n\n const ruleTestPath = `./test/rules/assertions/${camelCasedRuleName}.js`;\n if (!existsSync(ruleTestPath)) {\n await fs.writeFile(ruleTestPath, ruleTestTemplate);\n }\n\n const ruleReadmeTemplate = `### \\`${ruleName}\\`\n\n|||\n|---|---|\n|Context|everywhere|\n|Tags|\\`\\`|\n|Recommended|${recommended ? 'true' : 'false'}|\n|Settings||\n|Options||\n\n<!-- assertions ${camelCasedRuleName} -->\n`;\n\n const ruleReadmePath = `./.README/rules/${ruleName}.md`;\n if (!existsSync(ruleReadmePath)) {\n await fs.writeFile(ruleReadmePath, ruleReadmeTemplate);\n }\n\n const replaceInOrder = async ({\n path,\n oldRegex,\n checkName,\n newLine,\n oldIsCamel,\n }) => {\n const offsets = [];\n\n let readme = await fs.readFile(path, 'utf8');\n readme.replace(\n oldRegex,\n (matchedLine, n1, offset, str, {\n oldRule,\n }) => {\n offsets.push({\n matchedLine,\n offset,\n oldRule,\n });\n },\n );\n\n offsets.sort(({\n oldRule,\n }, {\n oldRule: oldRuleB,\n }) => {\n // eslint-disable-next-line no-extra-parens\n return oldRule < oldRuleB ? -1 : (oldRule > oldRuleB ? 1 : 0);\n });\n\n let alreadyIncluded = false;\n const itemIndex = offsets.findIndex(({\n oldRule,\n }) => {\n alreadyIncluded ||= oldIsCamel ? camelCasedRuleName === oldRule : ruleName === oldRule;\n\n return oldIsCamel ? camelCasedRuleName < oldRule : ruleName < oldRule;\n });\n let item = itemIndex !== undefined && offsets[itemIndex];\n if (item && itemIndex === 0 &&\n\n // This property would not always be sufficient but in this case it is.\n oldIsCamel\n ) {\n item.offset = 0;\n }\n\n if (!item) {\n item = offsets.pop();\n item.offset += item.matchedLine.length;\n }\n\n if (alreadyIncluded) {\n console.log(`Rule name is already present in ${checkName}.`);\n } else {\n readme = readme.slice(0, item.offset) +\n (item.offset ? '\\n' : '') +\n newLine +\n (item.offset ? '' : '\\n') +\n readme.slice(item.offset);\n\n await fs.writeFile(path, readme);\n }\n };\n\n await replaceInOrder({\n checkName: 'README',\n newLine: `{\"gitdown\": \"include\", \"file\": \"./rules/${ruleName}.md\"}`,\n oldRegex: /\\n\\{\"gitdown\": \"include\", \"file\": \".\\/rules\\/(?<oldRule>[^.]*).md\"\\}/gu,\n path: './.README/README.md',\n });\n\n await replaceInOrder({\n checkName: 'index import',\n newLine: `import ${camelCasedRuleName} from './rules/${camelCasedRuleName}';`,\n oldIsCamel: true,\n oldRegex: /\\nimport (?<oldRule>[^ ]*) from '.\\/rules\\/\\1';/gu,\n path: './src/index.js',\n });\n\n await replaceInOrder({\n checkName: 'index recommended',\n newLine: `${' '.repeat(6)}'jsdoc/${ruleName}': ${recommended ? 'warnOrError' : '\\'off\\''},`,\n oldRegex: /\\n\\s{6}'jsdoc\\/(?<oldRule>[^']*)': .*?,/gu,\n path: './src/index.js',\n });\n\n await replaceInOrder({\n checkName: 'index rules',\n newLine: `${' '.repeat(4)}'${ruleName}': ${camelCasedRuleName},`,\n oldRegex: /\\n\\s{4}'(?<oldRule>[^']*)': [^,]*,/gu,\n path: './src/index.js',\n });\n\n await import('./generateReadme.js');\n\n /*\n console.log('Paths to open for further editing\\n');\n console.log(`open ${ruleReadmePath}`);\n console.log(`open ${rulePath}`);\n console.log(`open ${ruleTestPath}\\n`);\n */\n\n // Set chdir as somehow still in operation from other test\n process.chdir(resolve(__dirname, '../../'));\n await open([\n // Could even add editor line column numbers like `${rulePath}:1:1`\n ruleReadmePath,\n ruleTestPath,\n rulePath,\n ]);\n})();\n"],"mappings":";;AAUA,IAAAA,GAAA,GAAAC,OAAA;AAGA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAGA,IAAAI,UAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,WAAA,GAAAH,sBAAA,CA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CAAC;IACnBG,SAAS,EAAE,QAAQ;IACnBC,OAAO,EAAG,2CAA0CjC,QAAS,OAAM;IACnE+B,QAAQ,EAAE,wEAAwE;IAClFD,IAAI,EAAE;EACR,CAAC,CAAC;EAEF,MAAMD,cAAc,CAAC;IACnBG,SAAS,EAAE,cAAc;IACzBC,OAAO,EAAG,UAASZ,kBAAmB,kBAAiBA,kBAAmB,IAAG;IAC7Ea,UAAU,EAAE,IAAI;IAChBH,QAAQ,EAAE,mDAAmD;IAC7DD,IAAI,EAAE;EACR,CAAC,CAAC;EAEF,MAAMD,cAAc,CAAC;IACnBG,SAAS,EAAE,mBAAmB;IAC9BC,OAAO,EAAG,GAAE,GAAG,CAACmB,MAAM,CAAC,CAAC,CAAE,UAASpD,QAAS,MAAKI,WAAW,GAAG,aAAa,GAAG,SAAU,GAAE;IAC3F2B,QAAQ,EAAE,2CAA2C;IACrDD,IAAI,EAAE;EACR,CAAC,CAAC;EAEF,MAAMD,cAAc,CAAC;IACnBG,SAAS,EAAE,aAAa;IACxBC,OAAO,EAAG,GAAE,GAAG,CAACmB,MAAM,CAAC,CAAC,CAAE,IAAGpD,QAAS,MAAKqB,kBAAmB,GAAE;IAChEU,QAAQ,EAAE,sCAAsC;IAChDD,IAAI,EAAE;EACR,CAAC,CAAC;EAEF,MAAAuB,OAAA,CAAAC,OAAA,GAAAC,IAAA,OAAAtE,uBAAA,CAAAd,OAAA,CAAa,qBAAqB,GAAC;;EAEnC;AACF;AACA;AACA;AACA;AACA;;EAEE;EACA+B,OAAO,CAACsD,KAAK,CAAC,IAAAF,aAAO,EAACG,SAAS,EAAE,QAAQ,CAAC,CAAC;EAC3C,MAAM,IAAAC,mBAAI,EAAC;EACT;EACA9B,cAAc,EACdF,YAAY,EACZH,QAAQ,CACT,CAAC;AACJ,CAAC,GAAG"}
|
|
1
|
+
{"version":3,"file":"generateRule.js","names":["_fs","require","_promises","_interopRequireDefault","_path","_camelcase","_openEditor","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","_interopRequireWildcard","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ruleName","options","process","argv","recommended","includes","console","error","test","ruleNamesPath","ruleNames","JSON","parse","fs","readFile","push","sort","writeFile","stringify","log","ruleTemplate","camelCasedRuleName","camelCase","rulePath","existsSync","ruleTestTemplate","ruleTestPath","ruleReadmeTemplate","ruleReadmePath","replaceInOrder","path","oldRegex","checkName","newLine","oldIsCamel","offsets","readme","replace","matchedLine","n1","offset","str","oldRule","oldRuleB","alreadyIncluded","itemIndex","findIndex","item","undefined","pop","length","slice","repeat","Promise","resolve","then","chdir","__dirname","open"],"sources":["../../src/bin/generateRule.js"],"sourcesContent":["/* eslint-disable no-console -- CLI */\n\n/**\n * @example\n *\n * ```shell\n * npm run create-rule my-new-rule -- --recommended\n * ```\n */\n\nimport {\n existsSync,\n} from 'fs';\nimport fs from 'fs/promises';\nimport {\n resolve,\n} from 'path';\nimport camelCase from 'camelcase';\nimport open from 'open-editor';\n\n// Todo: Would ideally have prompts, e.g., to ask for whether type was problem/layout, etc.\n\nconst [\n , , ruleName,\n ...options\n] = process.argv;\n\nconst recommended = options.includes('--recommended');\n\n(async () => {\n if (!ruleName) {\n console.error('Please supply a rule name');\n\n return;\n }\n\n if ((/[A-Z]/u).test(ruleName)) {\n console.error('Please ensure the rule has no capital letters');\n\n return;\n }\n\n const ruleNamesPath = './test/rules/ruleNames.json';\n const ruleNames = JSON.parse(await fs.readFile(\n ruleNamesPath, 'utf8',\n ));\n if (!ruleNames.includes(ruleName)) {\n ruleNames.push(ruleName);\n ruleNames.sort();\n }\n\n await fs.writeFile(ruleNamesPath, JSON.stringify(ruleNames, null, 2) + '\\n');\n console.log('ruleNames', ruleNames);\n\n const ruleTemplate = `import iterateJsdoc from '../iterateJsdoc';\n\nexport default iterateJsdoc(({\n context,\n utils,\n}) => {\n // Rule here\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: '',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-${ruleName}',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n // Option properties here (or remove the object)\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n`;\n\n const camelCasedRuleName = camelCase(ruleName);\n\n const rulePath = `./src/rules/${camelCasedRuleName}.js`;\n\n if (!existsSync(rulePath)) {\n await fs.writeFile(rulePath, ruleTemplate);\n }\n\n const ruleTestTemplate = `export default {\n invalid: [\n {\n code: \\`\n \\`,\n errors: [\n {\n line: 2,\n message: '',\n },\n ],\n },\n ],\n valid: [\n {\n code: \\`\n \\`,\n },\n ],\n};\n`;\n\n const ruleTestPath = `./test/rules/assertions/${camelCasedRuleName}.js`;\n if (!existsSync(ruleTestPath)) {\n await fs.writeFile(ruleTestPath, ruleTestTemplate);\n }\n\n const ruleReadmeTemplate = `### \\`${ruleName}\\`\n\n|||\n|---|---|\n|Context|everywhere|\n|Tags|\\`\\`|\n|Recommended|${recommended ? 'true' : 'false'}|\n|Settings||\n|Options||\n\n<!-- assertions ${camelCasedRuleName} -->\n`;\n\n const ruleReadmePath = `./.README/rules/${ruleName}.md`;\n if (!existsSync(ruleReadmePath)) {\n await fs.writeFile(ruleReadmePath, ruleReadmeTemplate);\n }\n\n const replaceInOrder = async ({\n path,\n oldRegex,\n checkName,\n newLine,\n oldIsCamel,\n }) => {\n const offsets = [];\n\n let readme = await fs.readFile(path, 'utf8');\n readme.replace(\n oldRegex,\n (matchedLine, n1, offset, str, {\n oldRule,\n }) => {\n offsets.push({\n matchedLine,\n offset,\n oldRule,\n });\n },\n );\n\n offsets.sort(({\n oldRule,\n }, {\n oldRule: oldRuleB,\n }) => {\n // eslint-disable-next-line no-extra-parens\n return oldRule < oldRuleB ? -1 : (oldRule > oldRuleB ? 1 : 0);\n });\n\n let alreadyIncluded = false;\n const itemIndex = offsets.findIndex(({\n oldRule,\n }) => {\n alreadyIncluded ||= oldIsCamel ? camelCasedRuleName === oldRule : ruleName === oldRule;\n\n return oldIsCamel ? camelCasedRuleName < oldRule : ruleName < oldRule;\n });\n let item = itemIndex !== undefined && offsets[itemIndex];\n if (item && itemIndex === 0 &&\n\n // This property would not always be sufficient but in this case it is.\n oldIsCamel\n ) {\n item.offset = 0;\n }\n\n if (!item) {\n item = offsets.pop();\n item.offset += item.matchedLine.length;\n }\n\n if (alreadyIncluded) {\n console.log(`Rule name is already present in ${checkName}.`);\n } else {\n readme = readme.slice(0, item.offset) +\n (item.offset ? '\\n' : '') +\n newLine +\n (item.offset ? '' : '\\n') +\n readme.slice(item.offset);\n\n await fs.writeFile(path, readme);\n }\n };\n\n await replaceInOrder({\n checkName: 'README',\n newLine: `{\"gitdown\": \"include\", \"file\": \"./rules/${ruleName}.md\"}`,\n oldRegex: /\\n\\{\"gitdown\": \"include\", \"file\": \".\\/rules\\/(?<oldRule>[^.]*).md\"\\}/gu,\n path: './.README/README.md',\n });\n\n await replaceInOrder({\n checkName: 'index import',\n newLine: `import ${camelCasedRuleName} from './rules/${camelCasedRuleName}';`,\n oldIsCamel: true,\n oldRegex: /\\nimport (?<oldRule>[^ ]*) from '.\\/rules\\/\\1';/gu,\n path: './src/index.js',\n });\n\n await replaceInOrder({\n checkName: 'index recommended',\n newLine: `${' '.repeat(6)}'jsdoc/${ruleName}': ${recommended ? 'warnOrError' : '\\'off\\''},`,\n oldRegex: /\\n\\s{6}'jsdoc\\/(?<oldRule>[^']*)': .*?,/gu,\n path: './src/index.js',\n });\n\n await replaceInOrder({\n checkName: 'index rules',\n newLine: `${' '.repeat(4)}'${ruleName}': ${camelCasedRuleName},`,\n oldRegex: /\\n\\s{4}'(?<oldRule>[^']*)': [^,]*,/gu,\n path: './src/index.js',\n });\n\n await import('./generateReadme.js');\n\n /*\n console.log('Paths to open for further editing\\n');\n console.log(`open ${ruleReadmePath}`);\n console.log(`open ${rulePath}`);\n console.log(`open ${ruleTestPath}\\n`);\n */\n\n // Set chdir as somehow still in operation from other test\n process.chdir(resolve(__dirname, '../../'));\n await open([\n // Could even add editor line column numbers like `${rulePath}:1:1`\n ruleReadmePath,\n ruleTestPath,\n rulePath,\n ]);\n})();\n"],"mappings":";;AAUA,IAAAA,GAAA,GAAAC,OAAA;AAGA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAGA,IAAAI,UAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,WAAA,GAAAH,sBAAA,CAAAF,OAAA;AAA+B,SAAAE,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAI,wBAAAR,GAAA,EAAAI,WAAA,SAAAA,WAAA,IAAAJ,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAS,KAAA,GAAAN,wBAAA,CAAAC,WAAA,OAAAK,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAV,GAAA,YAAAS,KAAA,CAAAE,GAAA,CAAAX,GAAA,SAAAY,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAjB,GAAA,QAAAiB,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAApB,GAAA,EAAAiB,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CA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qBAAqB,GAAC;;EAEnC;AACF;AACA;AACA;AACA;AACA;;EAEE;EACA+B,OAAO,CAACsD,KAAK,CAAC,IAAAF,aAAO,EAACG,SAAS,EAAE,QAAQ,CAAC,CAAC;EAC3C,MAAM,IAAAC,mBAAI,EAAC;EACT;EACA9B,cAAc,EACdF,YAAY,EACZH,QAAQ,CACT,CAAC;AACJ,CAAC,GAAG"}
|
package/dist/generateRule.js
CHANGED
|
@@ -45,7 +45,7 @@ export default iterateJsdoc(({
|
|
|
45
45
|
},
|
|
46
46
|
schema: [
|
|
47
47
|
{
|
|
48
|
-
|
|
48
|
+
additionalProperties: false,
|
|
49
49
|
properties: {
|
|
50
50
|
// Option properties here (or remove the object)
|
|
51
51
|
},
|
|
@@ -68,7 +68,7 @@ export default iterateJsdoc(({
|
|
|
68
68
|
\`,
|
|
69
69
|
errors: [
|
|
70
70
|
{
|
|
71
|
-
line:
|
|
71
|
+
line: 2,
|
|
72
72
|
message: '',
|
|
73
73
|
},
|
|
74
74
|
],
|
package/dist/generateRule.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRule.js","names":["_fs","require","_promises","_interopRequireDefault","_path","_camelcase","_openEditor","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","_interopRequireWildcard","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ruleName","options","process","argv","recommended","includes","console","error","test","ruleNamesPath","ruleNames","JSON","parse","fs","readFile","push","sort","writeFile","stringify","log","ruleTemplate","camelCasedRuleName","camelCase","rulePath","existsSync","ruleTestTemplate","ruleTestPath","ruleReadmeTemplate","ruleReadmePath","replaceInOrder","path","oldRegex","checkName","newLine","oldIsCamel","offsets","readme","replace","matchedLine","n1","offset","str","oldRule","oldRuleB","alreadyIncluded","itemIndex","findIndex","item","undefined","pop","length","slice","repeat","Promise","resolve","then","chdir","__dirname","open"],"sources":["../src/bin/generateRule.js"],"sourcesContent":["/* eslint-disable no-console -- CLI */\n\n/**\n * @example\n *\n * ```shell\n * npm run create-rule my-new-rule -- --recommended\n * ```\n */\n\nimport {\n existsSync,\n} from 'fs';\nimport fs from 'fs/promises';\nimport {\n resolve,\n} from 'path';\nimport camelCase from 'camelcase';\nimport open from 'open-editor';\n\n// Todo: Would ideally have prompts, e.g., to ask for whether type was problem/layout, etc.\n\nconst [\n , , ruleName,\n ...options\n] = process.argv;\n\nconst recommended = options.includes('--recommended');\n\n(async () => {\n if (!ruleName) {\n console.error('Please supply a rule name');\n\n return;\n }\n\n if ((/[A-Z]/u).test(ruleName)) {\n console.error('Please ensure the rule has no capital letters');\n\n return;\n }\n\n const ruleNamesPath = './test/rules/ruleNames.json';\n const ruleNames = JSON.parse(await fs.readFile(\n ruleNamesPath, 'utf8',\n ));\n if (!ruleNames.includes(ruleName)) {\n ruleNames.push(ruleName);\n ruleNames.sort();\n }\n\n await fs.writeFile(ruleNamesPath, JSON.stringify(ruleNames, null, 2) + '\\n');\n console.log('ruleNames', ruleNames);\n\n const ruleTemplate = `import iterateJsdoc from '../iterateJsdoc';\n\nexport default iterateJsdoc(({\n context,\n utils,\n}) => {\n // Rule here\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: '',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-${ruleName}',\n },\n schema: [\n {\n additionalProperies: false,\n properties: {\n // Option properties here (or remove the object)\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n`;\n\n const camelCasedRuleName = camelCase(ruleName);\n\n const rulePath = `./src/rules/${camelCasedRuleName}.js`;\n\n if (!existsSync(rulePath)) {\n await fs.writeFile(rulePath, ruleTemplate);\n }\n\n const ruleTestTemplate = `export default {\n invalid: [\n {\n code: \\`\n \\`,\n errors: [\n {\n line: '',\n message: '',\n },\n ],\n },\n ],\n valid: [\n {\n code: \\`\n \\`,\n },\n ],\n};\n`;\n\n const ruleTestPath = `./test/rules/assertions/${camelCasedRuleName}.js`;\n if (!existsSync(ruleTestPath)) {\n await fs.writeFile(ruleTestPath, ruleTestTemplate);\n }\n\n const ruleReadmeTemplate = `### \\`${ruleName}\\`\n\n|||\n|---|---|\n|Context|everywhere|\n|Tags|\\`\\`|\n|Recommended|${recommended ? 'true' : 'false'}|\n|Settings||\n|Options||\n\n<!-- assertions ${camelCasedRuleName} -->\n`;\n\n const ruleReadmePath = `./.README/rules/${ruleName}.md`;\n if (!existsSync(ruleReadmePath)) {\n await fs.writeFile(ruleReadmePath, ruleReadmeTemplate);\n }\n\n const replaceInOrder = async ({\n path,\n oldRegex,\n checkName,\n newLine,\n oldIsCamel,\n }) => {\n const offsets = [];\n\n let readme = await fs.readFile(path, 'utf8');\n readme.replace(\n oldRegex,\n (matchedLine, n1, offset, str, {\n oldRule,\n }) => {\n offsets.push({\n matchedLine,\n offset,\n oldRule,\n });\n },\n );\n\n offsets.sort(({\n oldRule,\n }, {\n oldRule: oldRuleB,\n }) => {\n // eslint-disable-next-line no-extra-parens\n return oldRule < oldRuleB ? -1 : (oldRule > oldRuleB ? 1 : 0);\n });\n\n let alreadyIncluded = false;\n const itemIndex = offsets.findIndex(({\n oldRule,\n }) => {\n alreadyIncluded ||= oldIsCamel ? camelCasedRuleName === oldRule : ruleName === oldRule;\n\n return oldIsCamel ? camelCasedRuleName < oldRule : ruleName < oldRule;\n });\n let item = itemIndex !== undefined && offsets[itemIndex];\n if (item && itemIndex === 0 &&\n\n // This property would not always be sufficient but in this case it is.\n oldIsCamel\n ) {\n item.offset = 0;\n }\n\n if (!item) {\n item = offsets.pop();\n item.offset += item.matchedLine.length;\n }\n\n if (alreadyIncluded) {\n console.log(`Rule name is already present in ${checkName}.`);\n } else {\n readme = readme.slice(0, item.offset) +\n (item.offset ? '\\n' : '') +\n newLine +\n (item.offset ? '' : '\\n') +\n readme.slice(item.offset);\n\n await fs.writeFile(path, readme);\n }\n };\n\n await replaceInOrder({\n checkName: 'README',\n newLine: `{\"gitdown\": \"include\", \"file\": \"./rules/${ruleName}.md\"}`,\n oldRegex: /\\n\\{\"gitdown\": \"include\", \"file\": \".\\/rules\\/(?<oldRule>[^.]*).md\"\\}/gu,\n path: './.README/README.md',\n });\n\n await replaceInOrder({\n checkName: 'index import',\n newLine: `import ${camelCasedRuleName} from './rules/${camelCasedRuleName}';`,\n oldIsCamel: true,\n oldRegex: /\\nimport (?<oldRule>[^ ]*) from '.\\/rules\\/\\1';/gu,\n path: './src/index.js',\n });\n\n await replaceInOrder({\n checkName: 'index recommended',\n newLine: `${' '.repeat(6)}'jsdoc/${ruleName}': ${recommended ? 'warnOrError' : '\\'off\\''},`,\n oldRegex: /\\n\\s{6}'jsdoc\\/(?<oldRule>[^']*)': .*?,/gu,\n path: './src/index.js',\n });\n\n await replaceInOrder({\n checkName: 'index rules',\n newLine: `${' '.repeat(4)}'${ruleName}': ${camelCasedRuleName},`,\n oldRegex: /\\n\\s{4}'(?<oldRule>[^']*)': [^,]*,/gu,\n path: './src/index.js',\n });\n\n await import('./generateReadme.js');\n\n /*\n console.log('Paths to open for further editing\\n');\n console.log(`open ${ruleReadmePath}`);\n console.log(`open ${rulePath}`);\n console.log(`open ${ruleTestPath}\\n`);\n */\n\n // Set chdir as somehow still in operation from other test\n process.chdir(resolve(__dirname, '../../'));\n await open([\n // Could even add editor line column numbers like `${rulePath}:1:1`\n ruleReadmePath,\n ruleTestPath,\n rulePath,\n ]);\n})();\n"],"mappings":";;AAUA,IAAAA,GAAA,GAAAC,OAAA;AAGA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAGA,IAAAI,UAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,WAAA,GAAAH,sBAAA,CAAAF,OAAA;AAA+B,SAAAE,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,E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ClFD,IAAI,EAAE;EACR,CAAC,CAAC;EAEF,MAAMD,cAAc,CAAC;IACnBG,SAAS,EAAE,cAAc;IACzBC,OAAO,EAAG,UAASZ,kBAAmB,kBAAiBA,kBAAmB,IAAG;IAC7Ea,UAAU,EAAE,IAAI;IAChBH,QAAQ,EAAE,mDAAmD;IAC7DD,IAAI,EAAE;EACR,CAAC,CAAC;EAEF,MAAMD,cAAc,CAAC;IACnBG,SAAS,EAAE,mBAAmB;IAC9BC,OAAO,EAAG,GAAE,GAAG,CAACmB,MAAM,CAAC,CAAC,CAAE,UAASpD,QAAS,MAAKI,WAAW,GAAG,aAAa,GAAG,SAAU,GAAE;IAC3F2B,QAAQ,EAAE,2CAA2C;IACrDD,IAAI,EAAE;EACR,CAAC,CAAC;EAEF,MAAMD,cAAc,CAAC;IACnBG,SAAS,EAAE,aAAa;IACxBC,OAAO,EAAG,GAAE,GAAG,CAACmB,MAAM,CAAC,CAAC,CAAE,IAAGpD,QAAS,MAAKqB,kBAAmB,GAAE;IAChEU,QAAQ,EAAE,sCAAsC;IAChDD,IAAI,EAAE;EACR,CAAC,CAAC;EAEF,MAAAuB,OAAA,CAAAC,OAAA,GAAAC,IAAA,OAAAtE,uBAAA,CAAAd,OAAA,CAAa,qBAAqB,GAAC;;EAEnC;AACF;AACA;AACA;AACA;AACA;;EAEE;EACA+B,OAAO,CAACsD,KAAK,CAAC,IAAAF,aAAO,EAACG,SAAS,EAAE,QAAQ,CAAC,CAAC;EAC3C,MAAM,IAAAC,mBAAI,EAAC;EACT;EACA9B,cAAc,EACdF,YAAY,EACZH,QAAQ,CACT,CAAC;AACJ,CAAC,GAAG"}
|
|
1
|
+
{"version":3,"file":"generateRule.js","names":["_fs","require","_promises","_interopRequireDefault","_path","_camelcase","_openEditor","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","_interopRequireWildcard","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ruleName","options","process","argv","recommended","includes","console","error","test","ruleNamesPath","ruleNames","JSON","parse","fs","readFile","push","sort","writeFile","stringify","log","ruleTemplate","camelCasedRuleName","camelCase","rulePath","existsSync","ruleTestTemplate","ruleTestPath","ruleReadmeTemplate","ruleReadmePath","replaceInOrder","path","oldRegex","checkName","newLine","oldIsCamel","offsets","readme","replace","matchedLine","n1","offset","str","oldRule","oldRuleB","alreadyIncluded","itemIndex","findIndex","item","undefined","pop","length","slice","repeat","Promise","resolve","then","chdir","__dirname","open"],"sources":["../src/bin/generateRule.js"],"sourcesContent":["/* eslint-disable no-console -- CLI */\n\n/**\n * @example\n *\n * ```shell\n * npm run create-rule my-new-rule -- --recommended\n * ```\n */\n\nimport {\n existsSync,\n} from 'fs';\nimport fs from 'fs/promises';\nimport {\n resolve,\n} from 'path';\nimport camelCase from 'camelcase';\nimport open from 'open-editor';\n\n// Todo: Would ideally have prompts, e.g., to ask for whether type was problem/layout, etc.\n\nconst [\n , , ruleName,\n ...options\n] = process.argv;\n\nconst recommended = options.includes('--recommended');\n\n(async () => {\n if (!ruleName) {\n console.error('Please supply a rule name');\n\n return;\n }\n\n if ((/[A-Z]/u).test(ruleName)) {\n console.error('Please ensure the rule has no capital letters');\n\n return;\n }\n\n const ruleNamesPath = './test/rules/ruleNames.json';\n const ruleNames = JSON.parse(await fs.readFile(\n ruleNamesPath, 'utf8',\n ));\n if (!ruleNames.includes(ruleName)) {\n ruleNames.push(ruleName);\n ruleNames.sort();\n }\n\n await fs.writeFile(ruleNamesPath, JSON.stringify(ruleNames, null, 2) + '\\n');\n console.log('ruleNames', ruleNames);\n\n const ruleTemplate = `import iterateJsdoc from '../iterateJsdoc';\n\nexport default iterateJsdoc(({\n context,\n utils,\n}) => {\n // Rule here\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: '',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-${ruleName}',\n },\n schema: [\n {\n additionalProperties: false,\n properties: {\n // Option properties here (or remove the object)\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n`;\n\n const camelCasedRuleName = camelCase(ruleName);\n\n const rulePath = `./src/rules/${camelCasedRuleName}.js`;\n\n if (!existsSync(rulePath)) {\n await fs.writeFile(rulePath, ruleTemplate);\n }\n\n const ruleTestTemplate = `export default {\n invalid: [\n {\n code: \\`\n \\`,\n errors: [\n {\n line: 2,\n message: '',\n },\n ],\n },\n ],\n valid: [\n {\n code: \\`\n \\`,\n },\n ],\n};\n`;\n\n const ruleTestPath = `./test/rules/assertions/${camelCasedRuleName}.js`;\n if (!existsSync(ruleTestPath)) {\n await fs.writeFile(ruleTestPath, ruleTestTemplate);\n }\n\n const ruleReadmeTemplate = `### \\`${ruleName}\\`\n\n|||\n|---|---|\n|Context|everywhere|\n|Tags|\\`\\`|\n|Recommended|${recommended ? 'true' : 'false'}|\n|Settings||\n|Options||\n\n<!-- assertions ${camelCasedRuleName} -->\n`;\n\n const ruleReadmePath = `./.README/rules/${ruleName}.md`;\n if (!existsSync(ruleReadmePath)) {\n await fs.writeFile(ruleReadmePath, ruleReadmeTemplate);\n }\n\n const replaceInOrder = async ({\n path,\n oldRegex,\n checkName,\n newLine,\n oldIsCamel,\n }) => {\n const offsets = [];\n\n let readme = await fs.readFile(path, 'utf8');\n readme.replace(\n oldRegex,\n (matchedLine, n1, offset, str, {\n oldRule,\n }) => {\n offsets.push({\n matchedLine,\n offset,\n oldRule,\n });\n },\n );\n\n offsets.sort(({\n oldRule,\n }, {\n oldRule: oldRuleB,\n }) => {\n // eslint-disable-next-line no-extra-parens\n return oldRule < oldRuleB ? -1 : (oldRule > oldRuleB ? 1 : 0);\n });\n\n let alreadyIncluded = false;\n const itemIndex = offsets.findIndex(({\n oldRule,\n }) => {\n alreadyIncluded ||= oldIsCamel ? camelCasedRuleName === oldRule : ruleName === oldRule;\n\n return oldIsCamel ? camelCasedRuleName < oldRule : ruleName < oldRule;\n });\n let item = itemIndex !== undefined && offsets[itemIndex];\n if (item && itemIndex === 0 &&\n\n // This property would not always be sufficient but in this case it is.\n oldIsCamel\n ) {\n item.offset = 0;\n }\n\n if (!item) {\n item = offsets.pop();\n item.offset += item.matchedLine.length;\n }\n\n if (alreadyIncluded) {\n console.log(`Rule name is already present in ${checkName}.`);\n } else {\n readme = readme.slice(0, item.offset) +\n (item.offset ? '\\n' : '') +\n newLine +\n (item.offset ? '' : '\\n') +\n readme.slice(item.offset);\n\n await fs.writeFile(path, readme);\n }\n };\n\n await replaceInOrder({\n checkName: 'README',\n newLine: `{\"gitdown\": \"include\", \"file\": \"./rules/${ruleName}.md\"}`,\n oldRegex: /\\n\\{\"gitdown\": \"include\", \"file\": \".\\/rules\\/(?<oldRule>[^.]*).md\"\\}/gu,\n path: './.README/README.md',\n });\n\n await replaceInOrder({\n checkName: 'index import',\n newLine: `import ${camelCasedRuleName} from './rules/${camelCasedRuleName}';`,\n oldIsCamel: true,\n oldRegex: /\\nimport (?<oldRule>[^ ]*) from '.\\/rules\\/\\1';/gu,\n path: './src/index.js',\n });\n\n await replaceInOrder({\n checkName: 'index recommended',\n newLine: `${' '.repeat(6)}'jsdoc/${ruleName}': ${recommended ? 'warnOrError' : '\\'off\\''},`,\n oldRegex: /\\n\\s{6}'jsdoc\\/(?<oldRule>[^']*)': .*?,/gu,\n path: './src/index.js',\n });\n\n await replaceInOrder({\n checkName: 'index rules',\n newLine: `${' '.repeat(4)}'${ruleName}': ${camelCasedRuleName},`,\n oldRegex: /\\n\\s{4}'(?<oldRule>[^']*)': [^,]*,/gu,\n path: './src/index.js',\n });\n\n await import('./generateReadme.js');\n\n /*\n console.log('Paths to open for further editing\\n');\n console.log(`open ${ruleReadmePath}`);\n console.log(`open ${rulePath}`);\n console.log(`open ${ruleTestPath}\\n`);\n */\n\n // Set chdir as somehow still in operation from other test\n process.chdir(resolve(__dirname, '../../'));\n await open([\n // Could even add editor line column numbers like `${rulePath}:1:1`\n ruleRead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AS,EAAE,QAAQ,CAAC,CAAC;EAC3C,MAAM,IAAAC,mBAAI,EAAC;EACT;EACA9B,cAAc,EACdF,YAAY,EACZH,QAAQ,CACT,CAAC;AACJ,CAAC,GAAG"}
|
package/dist/iterateJsdoc.js
CHANGED
|
@@ -111,6 +111,14 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
|
|
|
111
111
|
report(msg, handler ? fixer => {
|
|
112
112
|
handler();
|
|
113
113
|
const replacement = utils.stringify(jsdoc, specRewire);
|
|
114
|
+
if (!replacement) {
|
|
115
|
+
const text = sourceCode.getText();
|
|
116
|
+
const lastLineBreakPos = text.slice(0, jsdocNode.range[0]).search(/\n[ \t]*$/u);
|
|
117
|
+
if (lastLineBreakPos > -1) {
|
|
118
|
+
return fixer.removeRange([lastLineBreakPos, jsdocNode.range[1]]);
|
|
119
|
+
}
|
|
120
|
+
return fixer.removeRange(/\s/u.test(text.charAt(jsdocNode.range[1])) ? [jsdocNode.range[0], jsdocNode.range[1] + 1] : jsdocNode.range);
|
|
121
|
+
}
|
|
114
122
|
return fixer.replaceText(jsdocNode, replacement);
|
|
115
123
|
} : null, tag, data);
|
|
116
124
|
};
|
|
@@ -233,10 +241,10 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
|
|
|
233
241
|
})
|
|
234
242
|
}];
|
|
235
243
|
};
|
|
236
|
-
utils.removeTag =
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
244
|
+
utils.removeTag = (tagIndex, {
|
|
245
|
+
removeEmptyBlock = false,
|
|
246
|
+
tagSourceOffset = 0
|
|
247
|
+
} = {}) => {
|
|
240
248
|
const {
|
|
241
249
|
source: tagSource
|
|
242
250
|
} = jsdoc.tags[tagIndex];
|
|
@@ -246,12 +254,9 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
|
|
|
246
254
|
number
|
|
247
255
|
}, tagIdx) => {
|
|
248
256
|
const sourceIndex = jsdoc.source.findIndex(({
|
|
249
|
-
number: srcNumber
|
|
250
|
-
tokens: {
|
|
251
|
-
end
|
|
252
|
-
}
|
|
257
|
+
number: srcNumber
|
|
253
258
|
}) => {
|
|
254
|
-
return number === srcNumber
|
|
259
|
+
return number === srcNumber;
|
|
255
260
|
});
|
|
256
261
|
// istanbul ignore else
|
|
257
262
|
if (sourceIndex > -1) {
|
|
@@ -259,16 +264,32 @@ const getUtils = (node, jsdoc, jsdocNode, settings, report, context, iteratingAl
|
|
|
259
264
|
tagSource.slice(tagIdx + 1).some(({
|
|
260
265
|
tokens: {
|
|
261
266
|
tag,
|
|
262
|
-
end
|
|
267
|
+
end: ending
|
|
263
268
|
}
|
|
264
269
|
}) => {
|
|
265
|
-
if (!tag && !
|
|
270
|
+
if (!tag && !ending) {
|
|
266
271
|
spliceCount++;
|
|
267
272
|
return false;
|
|
268
273
|
}
|
|
269
274
|
return true;
|
|
270
275
|
});
|
|
271
|
-
|
|
276
|
+
const spliceIdx = sourceIndex + tagSourceOffset;
|
|
277
|
+
const {
|
|
278
|
+
delimiter,
|
|
279
|
+
end
|
|
280
|
+
} = jsdoc.source[spliceIdx].tokens;
|
|
281
|
+
|
|
282
|
+
/* istanbul ignore if -- Currently want to clear entirely if removing tags */
|
|
283
|
+
if (!removeEmptyBlock && (end || delimiter === '/**')) {
|
|
284
|
+
const {
|
|
285
|
+
tokens
|
|
286
|
+
} = jsdoc.source[spliceIdx];
|
|
287
|
+
for (const item of ['tag', 'postTag', 'type', 'postType', 'name', 'postName', 'description']) {
|
|
288
|
+
tokens[item] = '';
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
jsdoc.source.splice(spliceIdx, spliceCount - tagSourceOffset);
|
|
292
|
+
}
|
|
272
293
|
tagSource.splice(tagIdx + tagSourceOffset, spliceCount - tagSourceOffset);
|
|
273
294
|
lastIndex = sourceIndex;
|
|
274
295
|
return true;
|