Skip to content

Commit

Permalink
Merge e5f0fc3 into 571d7e9
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Sep 6, 2022
2 parents 571d7e9 + e5f0fc3 commit 7fa3a20
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 57 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
16 changes: 16 additions & 0 deletions .changeset/config.json
@@ -0,0 +1,16 @@
{
"$schema": "https://unpkg.com/@changesets/config/schema.json",
"changelog": [
"@changesets/changelog-github",
{
"repo": "ota-meshi/eslint-plugin-yml"
}
],
"commit": false,
"linked": [],
"access": "restricted",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"bumpVersionsWithWorkspaceProtocolOnly": true,
"ignore": []
}
3 changes: 3 additions & 0 deletions .env-cmdrc
@@ -1,5 +1,8 @@
{
"version": {
"IN_VERSION_SCRIPT": "true"
},
"version-ci": {
"IN_VERSION_CI_SCRIPT": "true"
}
}
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -27,6 +27,7 @@ module.exports = {
"no-lonely-if": "off",
"new-cap": "off",
"no-shadow": "off",
"no-void": ["error", { allowAsStatement: true }],
"jsonc/array-element-newline": "off",
},
overrides: [
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/GHPages.yml
Expand Up @@ -32,6 +32,8 @@ jobs:
run: npm install
- name: Build docs
run: npm run docs:build
- name: Update docs
run: npm run update
- name: Setup Pages
uses: actions/configure-pages@v2
- name: Upload artifact
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/NodeCI.yml
Expand Up @@ -18,6 +18,8 @@ jobs:
run: npm install
- name: Lint
run: npm run lint
- name: Build
run: npm run build
test:
runs-on: ubuntu-latest
strategy:
Expand Down
28 changes: 0 additions & 28 deletions .github/workflows/NpmPublish.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/Release.yml
@@ -0,0 +1,39 @@
name: Release

on:
push:
branches:
- master

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install Dependencies
run: npm install

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# this expects you to have a npm script called version that runs some logic and then calls `changeset version`.
version: npm run version:ci
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: npm run release
commit: "chore: release eslint-plugin-yml"
title: "chore: release eslint-plugin-yml"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -28,6 +28,9 @@
"docs:build": "export NODE_OPTIONS=--openssl-legacy-provider && npm run build:ts && vuepress build docs --no-cache",
"preversion": "npm test && git add .",
"version": "env-cmd -e version npm run update && git add .",
"version:ci": "env-cmd -e version-ci npm run update && changeset version",
"prerelease": "npm run build",
"release": "changeset publish",
"update-fixtures": "npm run ts -- ./tools/update-fixtures.ts && npm run eslint-fix",
"ts": "node -r esbuild-register",
"mocha": "npm run ts -- ./node_modules/mocha/bin/mocha.js"
Expand Down Expand Up @@ -60,6 +63,8 @@
"eslint": ">=6.0.0"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.6",
"@changesets/cli": "^2.24.2",
"@ota-meshi/eslint-plugin": "^0.12.0",
"@types/debug": "^4.1.5",
"@types/eslint": "^8.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Expand Up @@ -40,7 +40,6 @@ export interface RuleMetaData {
url: string;
ruleId: string;
ruleName: string;
replacedBy?: [];
default?: "error" | "warn";
extensionRule: string | false;
layout: boolean;
Expand All @@ -50,6 +49,7 @@ export interface RuleMetaData {
hasSuggestions?: boolean;
schema: JSONSchema4 | JSONSchema4[];
deprecated?: boolean;
replacedBy?: string[];
type: "problem" | "suggestion" | "layout";
}

Expand Down
27 changes: 27 additions & 0 deletions tools/lib/changesets-util.ts
@@ -0,0 +1,27 @@
import assembleReleasePlan from "@changesets/assemble-release-plan";
import readChangesets from "@changesets/read";
import { read } from "@changesets/config";
import { getPackages } from "@manypkg/get-packages";
import { readPreState } from "@changesets/pre";
import path from "path";

const root = path.resolve(__dirname, "../..");

/** Get new version string from changesets */
export async function getNewVersion(): Promise<string> {
const packages = await getPackages(root);
const preState = await readPreState(root);
const config = await read(root, packages);
const changesets = await readChangesets(root);

const releasePlan = assembleReleasePlan(
changesets,
packages,
config,
preState
);

return releasePlan.releases.find(
({ name }) => name === "eslint-plugin-svelte"
)!.newVersion;
}
77 changes: 50 additions & 27 deletions tools/update-docs.ts
Expand Up @@ -2,6 +2,7 @@ import path from "path";
import fs from "fs";
import { rules } from "../src/utils/rules";
import type { RuleModule } from "../src/types";
import { getNewVersion } from "./lib/changesets-util";

//eslint-disable-next-line require-jsdoc -- tools
function formatItems(items: string[]) {
Expand All @@ -24,7 +25,7 @@ function yamlValue(val: unknown) {
const ROOT = path.resolve(__dirname, "../docs/rules");

//eslint-disable-next-line require-jsdoc -- tools
function pickSince(content: string): string | null {
function pickSince(content: string): string | null | Promise<string> {
const fileIntro = /^---\n((?:.*\n)+)---\n*/.exec(content);
if (fileIntro) {
const since = /since: "?(v\d+\.\d+\.\d+)"?/.exec(fileIntro[1]);
Expand All @@ -37,6 +38,10 @@ function pickSince(content: string): string | null {
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports -- ignore
return `v${require("../package.json").version}`;
}
// eslint-disable-next-line no-process-env -- ignore
if (process.env.IN_VERSION_CI_SCRIPT) {
return getNewVersion().then((v) => `v${v}`);
}
return null;
}

Expand All @@ -47,7 +52,7 @@ class DocFile {

private content: string;

private readonly since: string | null;
private readonly since: string | null | Promise<string>;

public constructor(rule: RuleModule) {
this.rule = rule;
Expand All @@ -64,8 +69,10 @@ class DocFile {
const {
meta: {
fixable,
hasSuggestions,
deprecated,
docs: { ruleId, description, categories, replacedBy },
replacedBy,
docs: { ruleId, description, categories },
},
} = this.rule;
const title = `# ${ruleId}\n\n> ${description}`;
Expand Down Expand Up @@ -101,9 +108,14 @@ class DocFile {
"- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule."
);
}
if (hasSuggestions) {
notes.push(
"- :bulb: Some problems reported by this rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)."
);
}
if (!this.since) {
notes.unshift(
`- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>`
`- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> **_This rule has not been released yet._** </badge>`
);
}

Expand All @@ -112,27 +124,30 @@ class DocFile {
notes.push("", "");
}

const headerPattern = /#.+\n+[^\n]*\n+(?:- .+\n+)*\n*/u;
const headerPattern = /(?:^|\n)#.+\n+[^\n]*\n+(?:- .+\n+)*\n*/u;

const header = `${title}\n\n${notes.join("\n")}`;
const header = `\n${title}\n\n${notes.join("\n")}`;
if (headerPattern.test(this.content)) {
this.content = this.content.replace(headerPattern, header);
this.content = this.content.replace(
headerPattern,
header.replace(/\$/g, "$$$$")
);
} else {
this.content = `${header}${this.content.trim()}\n`;
}

return this;
}

public updateFooter() {
public async updateFooter() {
const { ruleName, extensionRule } = this.rule.meta.docs;
const footerPattern =
/## (?:(?::mag:)? ?Implementation|:rocket: Version).+$/s;
const footer = `${
this.since
? `## :rocket: Version
This rule was introduced in eslint-plugin-yml ${this.since}
This rule was introduced in eslint-plugin-yml ${await this.since}
`
: ""
Expand All @@ -149,7 +164,10 @@ ${
: ""
}`;
if (footerPattern.test(this.content)) {
this.content = this.content.replace(footerPattern, footer);
this.content = this.content.replace(
footerPattern,
footer.replace(/\$/g, "$$$$")
);
} else {
this.content = `${this.content.trim()}\n\n${footer}`;
}
Expand Down Expand Up @@ -190,25 +208,28 @@ ${
return this;
}

public updateFileIntro() {
public async updateFileIntro() {
const { ruleId, description } = this.rule.meta.docs;

const fileIntro = {
pageClass: "rule-details",
sidebarDepth: 0,
title: ruleId,
description,
...(this.since ? { since: this.since } : {}),
...(this.since ? { since: await this.since } : {}),
};
const computed = `---\n${Object.keys(fileIntro)
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- tool
.map((key) => `${key}: ${yamlValue((fileIntro as any)[key])}`)
.join("\n")}\n---\n`;
.join("\n")}\n---\n\n`;

const fileIntroPattern = /^---\n(.*\n)+?---\n*/gu;
const fileIntroPattern = /^---\n(?:.*\n)+?---\n*/gu;

if (fileIntroPattern.test(this.content)) {
this.content = this.content.replace(fileIntroPattern, computed);
this.content = this.content.replace(
fileIntroPattern,
computed.replace(/\$/g, "$$$$")
);
} else {
this.content = `${computed}${this.content.trim()}\n`;
}
Expand All @@ -217,21 +238,23 @@ ${
}

public write() {
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -- tools
const isWin = require("os").platform().startsWith("win");

this.content = this.content.replace(/\r?\n/gu, isWin ? "\r\n" : "\n");
this.content = this.content.replace(/\r?\n/gu, "\n");

fs.writeFileSync(this.filePath, this.content);
}
}

for (const rule of rules) {
DocFile.read(rule)
.updateHeader()
.updateFooter()
.updateCodeBlocks()
.updateFileIntro()
.adjustCodeBlocks()
.write();
void main();

/** main */
async function main() {
for (const rule of rules) {
const doc = DocFile.read(rule);
doc.updateHeader();
await doc.updateFooter();
doc.updateCodeBlocks();
await doc.updateFileIntro();
doc.adjustCodeBlocks();
doc.write();
}
}
4 changes: 3 additions & 1 deletion tsconfig.json
Expand Up @@ -18,7 +18,9 @@
// "*": ["typings/*"]
// },
"esModuleInterop": true,
"outDir": "lib"
"outDir": "lib",

"skipLibCheck": true
},
"include": [
"src/**/*",
Expand Down

0 comments on commit 7fa3a20

Please sign in to comment.