Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: show red underlines in examples in rules docs #18041

Merged
merged 28 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
11ead30
docs: show red underlines in examples in rules docs
ota-meshi Jan 27, 2024
bc1c2ac
fix: add postinstall to install eslint dependencies
ota-meshi Jan 27, 2024
cb53d9a
fix: after-tokenize hook
ota-meshi Jan 27, 2024
3ddd37b
fix: after-tokenize script
ota-meshi Jan 27, 2024
24472b7
fix: after-tokenize hook
ota-meshi Jan 27, 2024
88963fb
fix: after-tokenize hook
ota-meshi Jan 27, 2024
770999a
fix: comment
ota-meshi Jan 27, 2024
ab8eccb
fix: change to verify using the custom container parserOptions
ota-meshi Jan 28, 2024
97f5400
fix: refactor it so it doesn't affect tests
ota-meshi Jan 28, 2024
0e41484
fix bug for no-multiple-empty-lines
ota-meshi Jan 29, 2024
964fb95
fix: bug for eol-last
ota-meshi Jan 29, 2024
e4498ee
feat: use wavy line
ota-meshi Jan 30, 2024
960b13b
feat: refactor
ota-meshi Jan 30, 2024
e4f40d6
fix: refactor
ota-meshi Jan 31, 2024
675150c
feat: change to add message to title attribute
ota-meshi Feb 2, 2024
2ded89f
chore: revert scripts and change docs-ci
ota-meshi Feb 2, 2024
8588c3c
fix: prism-eslint-hook.js
ota-meshi Feb 2, 2024
d529339
fix: for unicode-bom
ota-meshi Feb 3, 2024
57d6793
fix: disabled mark process if no linter is available
ota-meshi Feb 19, 2024
9b4050d
Update docs/tools/prism-eslint-hook.js
ota-meshi Feb 20, 2024
6b1de56
chore: add fileoverview
ota-meshi Feb 20, 2024
1a515d2
chore: add netlify.toml
ota-meshi Feb 27, 2024
11622c1
fix: for unicode-bom with always
ota-meshi Feb 27, 2024
8398ad6
feat: improved styles for zero width markers.
ota-meshi Feb 28, 2024
78d9858
chore: fix format
ota-meshi Feb 28, 2024
541dbd1
Update syntax-highlighter.scss
ota-meshi Mar 4, 2024
0d2c80d
fix: issue with consecutive line breaks
ota-meshi Mar 5, 2024
f90b1d2
fix: hides marker on newline following the marker
ota-meshi Mar 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/docs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
working-directory: docs
run: npm install

- name: Install Packages
run: npm install --force

- name: Stylelint Docs
working-directory: docs
run: npm run lint:scss
Expand Down
6 changes: 5 additions & 1 deletion docs/.eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
} = require("luxon");
const markdownIt = require("markdown-it");
const markdownItRuleExample = require("./tools/markdown-it-rule-example");
const { addContentMustBeMarked } = require("./tools/prism-eslint-hook");

module.exports = function(eleventyConfig) {

Expand Down Expand Up @@ -194,7 +195,10 @@ module.exports = function(eleventyConfig) {

// markdown-it plugin options for playground-linked code blocks in rule examples.
const ruleExampleOptions = markdownItRuleExample({
open({ type, code, parserOptions, env }) {
open({ type, code, parserOptions, env, codeBlockToken }) {

addContentMustBeMarked(codeBlockToken.content, parserOptions);

const isRuleRemoved = !Object.hasOwn(env.rules_meta, env.title);

if (isRuleRemoved) {
Expand Down
2 changes: 2 additions & 0 deletions docs/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
command = "cd .. && npm install -f && cd ./docs && npm run build"
1 change: 1 addition & 0 deletions docs/src/_plugins/md-syntax-highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SOFTWARE.

const Prism = require("prismjs");
const loadLanguages = require("prismjs/components/");
require("../../tools/prism-eslint-hook").installPrismESLintMarkerHook();

/**
*
Expand Down
33 changes: 33 additions & 0 deletions docs/src/assets/scss/syntax-highlighter.scss
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,39 @@ pre[class*="language-"] {
cursor: help;
}

.token.eslint-marked {
/* Draw the wavy line. */
background:
url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%206%203'%20enable-background%3D'new%200%200%206%203'%20height%3D'3'%20width%3D'6'%3E%3Cg%20fill%3D'%23f14c4c'%3E%3Cpolygon%20points%3D'5.5%2C0%202.5%2C3%201.1%2C3%204.1%2C0'%2F%3E%3Cpolygon%20points%3D'4%2C0%206%2C2%206%2C0.6%205.4%2C0'%2F%3E%3Cpolygon%20points%3D'0%2C2%201%2C3%202.4%2C3%200%2C0.6'%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E")
repeat-x
bottom
left;

/*
* Since the character width of the token span is not constant,
* if we use it as is, we may see a shift in the border.
* To make the border shift less noticeable, draw it with a smaller width.
*/
background-size: 4.4px auto;
}

.token.eslint-marked-on-zero-width {
position: relative;

/* Delete the wavy line. */
background: none;
}

.token.eslint-marked-on-zero-width::before {
content: "";
position: absolute;
bottom: 0;
left: -2px;
border-left: 3px solid transparent;
border-right: 3px solid transparent;
border-bottom: 4px solid #d11;
}

.line-numbers-wrapper {
position: absolute;
top: 0;
Expand Down
26 changes: 26 additions & 0 deletions docs/tools/code-block-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @fileoverview A utility related to markdown code blocks.
* @author Yosuke Ota
*/
"use strict";

/**
* Replaces some marks used in the code in the document and converts it into parsable code.
* The replaced string will be used in the linter,
* so be careful not to replace characters that change the location of the line and column.
* @param {string} code The code in the document.
* @returns {string} The parsable code.
*/
function docsExampleCodeToParsableCode(code) {
return code

// Remove trailing newline and presentational `⏎` characters
.replace(/⏎(?=\n)/gu, "")

// Code blocks always contain extra line breaks, so remove them.
.replace(/\n$/u, "");
}

module.exports = {
docsExampleCodeToParsableCode
};
6 changes: 3 additions & 3 deletions docs/tools/markdown-it-rule-example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

const { docsExampleCodeToParsableCode } = require("./code-block-utils");

/** @typedef {import("../../lib/shared/types").ParserOptions} ParserOptions */

/**
Expand Down Expand Up @@ -75,9 +77,7 @@ function markdownItRuleExample({ open, close }) {
const codeBlockToken = tokens[index + 1];

// Remove trailing newline and presentational `⏎` characters (https://github.com/eslint/eslint/issues/17627):
const code = codeBlockToken.content
.replace(/\n$/u, "")
.replace(/⏎(?=\n)/gu, "");
const code = docsExampleCodeToParsableCode(codeBlockToken.content);

const text = open({ type, code, parserOptions, codeBlockToken, env });

Expand Down