Skip to content

Commit

Permalink
build: update scripts to use the new package name (eslint-community#6)
Browse files Browse the repository at this point in the history
* build: update scripts to the new package name

* fix: update rules.meta.replacedBy
  • Loading branch information
aladdin-add authored Jan 25, 2022
1 parent ffed3ed commit df759eb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/rules/no-unsupported-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,8 @@ module.exports = {
category: "Possible Errors",
recommended: false,
replacedBy: [
"node/no-unsupported-features/es-syntax",
"node/no-unsupported-features/es-builtins",
"n/no-unsupported-features/es-syntax",
"n/no-unsupported-features/es-builtins",
],
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unsupported-features.md",
Expand Down
6 changes: 3 additions & 3 deletions scripts/new-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ new RuleTester().run("${ruleId}", rule, {
👍 Examples of **correct** code for this rule:
\`\`\`js
/*eslint node/${ruleId}: error */
/*eslint n/${ruleId}: error */
\`\`\`
👎 Examples of **incorrect** code for this rule:
\`\`\`js
/*eslint node/${ruleId}: error */
/*eslint n/${ruleId}: error */
\`\`\`
## ⚙ Options
\`\`\`json
{
"node/${ruleId}": ["error", ...]
"n/${ruleId}": ["error", ...]
}
\`\`\`
`
Expand Down
7 changes: 4 additions & 3 deletions scripts/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
const path = require("path")
const glob = require("fast-glob")
const rootDir = path.resolve(__dirname, "../lib/rules/")
const {pluginName} = require("./utils");

/**
* @typedef {Object} RuleInfo
* @property {string} filePath The path to the rule definition.
* @property {string} id The rule ID. (This includes `node/` prefix.)
* @property {string} name The rule name. (This doesn't include `node/` prefix.)
* @property {string} id The rule ID. (This includes `n/` prefix.)
* @property {string} name The rule name. (This doesn't include `n/` prefix.)
* @property {string} category The category ID.
* @property {string} description The description of this rule.
* @property {boolean} recommended The flag to indicate a recommended rule.
Expand All @@ -38,7 +39,7 @@ const rules = glob
return Object.assign(
{
filePath,
id: `node/${name}`,
id: `${pluginName}/${name}`,
name,
deprecated: Boolean(meta.deprecated),
fixable: Boolean(meta.fixable),
Expand Down
4 changes: 2 additions & 2 deletions scripts/update-docs-header-and-footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function renderHeader(rule) {

if (rule.recommended) {
lines.push(
"> - ⭐️ This rule is included in `plugin:node/recommended` preset."
"> - ⭐️ This rule is included in `plugin:n/recommended` preset."
)
}
if (rule.fixable) {
Expand All @@ -36,7 +36,7 @@ function renderHeader(rule) {
}
if (rule.deprecated) {
const replace = rule.replacedBy.map(
ruleId => `[${ruleId}](./${ruleId.replace("node/", "")}.md)`
ruleId => `[${ruleId}](./${ruleId.replace(/^n\//, "")}.md)`
)
const replaceText =
replace.length === 0
Expand Down
6 changes: 4 additions & 2 deletions scripts/update-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
const fs = require("fs")
const path = require("path")
const { categories, rules } = require("./rules")
const { pluginName } = require("./utils")

/**
* Render a given rule as a table row.
Expand All @@ -27,10 +28,11 @@ function renderRule(rule) {
*/
function renderDeprecatedRule(rule) {
const link = `[${rule.id}](./docs/rules/${rule.name}.md)`
const pluginNameReg = new RegExp(`^${pluginName}[/]`, "u")
const replacedBy = rule.replacedBy
.map(nameRaw => {
const name = nameRaw.replace(/^node[/]/u, "")
return `[node/${name}](./docs/rules/${name}.md)`
const name = nameRaw.replace(pluginNameReg, "")
return `[${pluginName}/${name}](./docs/rules/${name}.md)`
})
.join(" and ")

Expand Down
5 changes: 5 additions & 0 deletions scripts/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const pkg = require('../package.json');
exports.pluginName = pkg.name.replace(/^eslint-plugin-/u, '');

0 comments on commit df759eb

Please sign in to comment.