@storm-software/markdownlint 0.1.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/.eslintrc.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "extends": ["../../.eslintrc.base.json"],
3
+ "ignorePatterns": ["!**/*", "node_modules/*"],
4
+ "overrides": [
5
+ {
6
+ "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
+ "rules": {}
8
+ },
9
+ {
10
+ "files": ["*.ts", "*.tsx"],
11
+ "rules": {}
12
+ },
13
+ {
14
+ "files": ["*.js", "*.jsx"],
15
+ "rules": {}
16
+ },
17
+ {
18
+ "files": ["*.json"],
19
+ "parser": "jsonc-eslint-parser",
20
+ "rules": {
21
+ "@nx/dependency-checks": [
22
+ "error",
23
+ {
24
+ "buildTargets": ["build"],
25
+ "ignoredFiles": [
26
+ "{projectRoot}/esbuild.config.{js,ts,mjs,mts}",
27
+ "{projectRoot}/jest.config.ts"
28
+ ],
29
+ "checkMissingDependencies": true,
30
+ "checkObsoleteDependencies": true,
31
+ "checkVersionMismatches": false
32
+ }
33
+ ]
34
+ }
35
+ }
36
+ ]
37
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## 0.1.0 (2024-05-06)
2
+
3
+
4
+ ### 🚀 Features
5
+
6
+ - **markdownlint:** Added the `markdownlint` package for shared configurations ([abd6fa38](https://github.com/storm-software/storm-ops/commit/abd6fa38))
7
+
8
+
9
+ ### ❤️ Thank You
10
+
11
+ - Patrick Sullivan
package/README.md ADDED
@@ -0,0 +1,217 @@
1
+ <!-- START header -->
2
+ <!-- prettier-ignore-start -->
3
+ <!-- markdownlint-disable -->
4
+
5
+
6
+ <div align="center"><img src="https://pub-761b436209f44a4d886487c917806c08.r2.dev/storm-banner.gif" width="100%" alt="Storm Software" /></div>
7
+ <br />
8
+
9
+ <div align="center">
10
+ <b>
11
+ <a href="https://stormsoftware.com" target="_blank">Website</a> •
12
+ <a href="https://github.com/storm-software/storm-ops" target="_blank">GitHub</a> •
13
+ <a href="https://discord.gg/MQ6YVzakM5">Discord</a> • <a href="https://stormstack.github.io/stormstack/" target="_blank">Docs</a> • <a href="https://stormsoftware.com/contact" target="_blank">Contact</a> •
14
+ <a href="https://github.com/storm-software/storm-ops/issues/new?assignees=&labels=bug&template=bug-report.yml&title=Bug Report%3A+">Report a Bug</a>
15
+ </b>
16
+ </div>
17
+
18
+ <br />
19
+ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages include CLI utility applications, tools, and various libraries used to create modern, scalable web applications.
20
+ <br />
21
+
22
+ <h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />
23
+
24
+ [![Version](https://img.shields.io/badge/version-2.9.4-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
25
+ [![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with docusaurus](https://img.shields.io/badge/documented_with-docusaurus-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://docusaurus.io/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-ops/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
26
+
27
+ > [!IMPORTANT]
28
+ > This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be availible through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.
29
+
30
+ <br />
31
+
32
+
33
+ <!-- markdownlint-restore -->
34
+ <!-- prettier-ignore-end -->
35
+
36
+ <!-- END header -->
37
+
38
+ # Storm Markdownlint Rules
39
+
40
+ An opinionated collection of markdownlint rules used by Storm Software. This package includes the rules used by GitHub in the [markdownlint-github](https://github.com/github/markdownlint-github) package, as well as additional rules that are specific to Storm Software.
41
+
42
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
43
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
44
+
45
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
46
+
47
+ ## Installing
48
+
49
+ Using [pnpm](http://pnpm.io):
50
+
51
+ ```bash
52
+ pnpm add -D @storm-software/markdownlint
53
+ ```
54
+
55
+ <details>
56
+ <summary>Using npm</summary>
57
+
58
+ ```bash
59
+ npm install -D @storm-software/markdownlint
60
+ ```
61
+
62
+ </details>
63
+
64
+ <details>
65
+ <summary>Using yarn</summary>
66
+
67
+ ```bash
68
+ yarn add -D @storm-software/markdownlint
69
+ ```
70
+
71
+ </details>
72
+
73
+ ## Building
74
+
75
+ Run `nx build markdownlint` to build the library.
76
+
77
+ ## Running unit tests
78
+
79
+ Run `nx test markdownlint` to execute the unit tests via [Jest](https://jestjs.io).
80
+
81
+ <!-- START footer -->
82
+ <!-- prettier-ignore-start -->
83
+ <!-- markdownlint-disable -->
84
+
85
+
86
+ ## Storm Workspaces
87
+
88
+ Storm workspaces are built using <a href="https://nx.dev/" target="_blank">Nx</a>, a set of extensible dev tools for monorepos, which helps you develop like Google, Facebook, and Microsoft. Building on top of Nx, the Open System provides a set of tools and patterns that help you scale your monorepo to many teams while keeping the codebase maintainable.
89
+
90
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
91
+ <br />
92
+
93
+ ## Roadmap
94
+
95
+ See the [open issues](https://github.com/storm-software/storm-ops/issues) for a list of proposed features (and known issues).
96
+
97
+ - [Top Feature Requests](https://github.com/storm-software/storm-ops/issues?q=label%3Aenhancement+is%3Aopen+sort%3Areactions-%2B1-desc) (Add your votes using the 👍 reaction)
98
+ - [Top Bugs](https://github.com/storm-software/storm-ops/issues?q=is%3Aissue+is%3Aopen+label%3Abug+sort%3Areactions-%2B1-desc) (Add your votes using the 👍 reaction)
99
+ - [Newest Bugs](https://github.com/storm-software/storm-ops/issues?q=is%3Aopen+is%3Aissue+label%3Abug)
100
+
101
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
102
+ <br />
103
+
104
+ ## Support
105
+
106
+ Reach out to the maintainer at one of the following places:
107
+
108
+ - [Contact](https://stormsoftware.com/contact)
109
+ - [GitHub discussions](https://github.com/storm-software/storm-ops/discussions)
110
+ - <support@stormsoftware.com>
111
+
112
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
113
+ <br />
114
+
115
+ ## License
116
+
117
+ This project is licensed under the **Apache License 2.0**. Feel free to edit and distribute this template as you like.
118
+
119
+ See [LICENSE](LICENSE) for more information.
120
+
121
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
122
+ <br />
123
+
124
+ ## Changelog
125
+
126
+ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Every release, along with the migration instructions, is documented in the [CHANGELOG](CHANGELOG.md) file
127
+
128
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
129
+ <br />
130
+
131
+ ## Contributing
132
+
133
+ First off, thanks for taking the time to contribute! Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are **greatly appreciated**.
134
+
135
+ Please try to create bug reports that are:
136
+
137
+ - _Reproducible._ Include steps to reproduce the problem.
138
+ - _Specific._ Include as much detail as possible: which version, what environment, etc.
139
+ - _Unique._ Do not duplicate existing opened issues.
140
+ - _Scoped to a Single Bug._ One bug per report.
141
+
142
+ Please adhere to this project's [code of conduct](.github/CODE_OF_CONDUCT.md).
143
+
144
+ You can use [markdownlint-cli](https://github.com/storm-software/storm-ops/markdownlint-cli) to check for common markdown style inconsistency.
145
+
146
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
147
+ <br />
148
+
149
+ ## Contributors
150
+
151
+ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
152
+
153
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
154
+
155
+ <table>
156
+ <tbody>
157
+ <tr>
158
+ <td align="center" valign="top" width="14.28%"><a href="http://www.sullypat.com/"><img src="https://avatars.githubusercontent.com/u/99053093?v=4?s=100" width="100px;" alt="Patrick Sullivan"/><br /><sub><b>Patrick Sullivan</b></sub></a><br /><a href="#design-sullivanpj" title="Design">🎨</a> <a href="https://github.com/storm-software/storm-ops/commits?author=sullivanpj" title="Code">💻</a> <a href="#tool-sullivanpj" title="Tools">🔧</a> <a href="https://github.com/storm-software/storm-ops/commits?author=sullivanpj" title="Documentation">📖</a> <a href="https://github.com/storm-software/storm-ops/commits?author=sullivanpj" title="Tests">⚠️</a></td>
159
+ <td align="center" valign="top" width="14.28%"><a href="https://tylerbenning.com/"><img src="https://avatars.githubusercontent.com/u/7265547?v=4?s=100" width="100px;" alt="Tyler Benning"/><br /><sub><b>Tyler Benning</b></sub></a><br /><a href="#design-tbenning" title="Design">🎨</a></td>
160
+ <td align="center" valign="top" width="14.28%"><a href="http://stormsoftware.com"><img src="https://avatars.githubusercontent.com/u/149802440?v=4?s=100" width="100px;" alt="Stormie"/><br /><sub><b>Stormie</b></sub></a><br /><a href="#maintenance-stormie-bot" title="Maintenance">🚧</a></td>
161
+ </tr>
162
+ </tbody>
163
+ <tfoot>
164
+ <tr>
165
+ <td align="center" size="13px" colspan="7">
166
+ <img src="https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg" alt="All Contributors">
167
+ <a href="https://all-contributors.js.org/docs/en/bot/usage">Add your contributions</a>
168
+ </img>
169
+ </td>
170
+ </tr>
171
+ </tfoot>
172
+ </table>
173
+
174
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
175
+
176
+ This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
177
+
178
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
179
+ <br />
180
+
181
+ <hr />
182
+ <br />
183
+
184
+ <div align="center">
185
+ <img src="https://pub-761b436209f44a4d886487c917806c08.r2.dev/logo-banner.png" width="100%" alt="Storm Software" />
186
+ </div>
187
+ <br />
188
+
189
+ <div align="center">
190
+ <b>
191
+ <a href="https://stormsoftware.com" target="_blank">Website</a> • <a href="https://stormsoftware.com/contact" target="_blank">Contact</a> • <a href="https://discord.gg/MQ6YVzakM5">Discord</a> • <a href="https://linkedin.com/in/pat-sullivan-dev" target="_blank">LinkedIn</a> • <a href="https://medium.com/@pat.joseph.sullivan" target="_blank">Medium</a> • <a href="https://github.com/storm-software" target="_blank">GitHub</a> • <a href="https://keybase.io/sullivanp" target="_blank">OpenPGP Key</a>
192
+ </b>
193
+ </div>
194
+
195
+ <div align="center">
196
+ <b>Fingerprint:</b> 1BD2 7192 7770 2549 F4C9 F238 E6AD C420 DA5C 4C2D
197
+ </div>
198
+ <br />
199
+
200
+ Storm Software is an open source software development organization and creator of Acidic, StormStack and StormCloud.
201
+
202
+ Our mission is to make software development more accessible. Our ideal future is one where anyone can create software without years of prior development experience serving as a barrier to entry. We hope to achieve this via LLMs, Generative AI, and intuitive, high-level data modeling/programming languages.
203
+
204
+ If this sounds interesting, and you would like to help us in creating the next generation of development tools, please reach out on our website!
205
+
206
+ <br />
207
+ <h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3>
208
+
209
+ <br />
210
+ <div align="right">[ <a href="#table-of-contents">Back to top ▲</a> ]</div>
211
+ <br />
212
+
213
+
214
+ <!-- markdownlint-restore -->
215
+ <!-- prettier-ignore-end -->
216
+
217
+ <!-- END footer -->
package/jest.config.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { getJestConfig } from "@storm-software/testing-tools";
2
+
3
+ export default getJestConfig("packages/markdownlint", true, "markdownlint");
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@storm-software/markdownlint",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "description": "⚡An opinionated collection of markdownlint rules used by Storm Software.",
6
+ "keywords": [
7
+ "storm",
8
+ "storm-ops",
9
+ "stormstack",
10
+ "storm-stack",
11
+ "sullivanpj",
12
+ "open-system",
13
+ "monorepo",
14
+ "markdownlint",
15
+ "markdownlint-cli",
16
+ "markdownlint-cli2"
17
+ ],
18
+ "homepage": "https://stormsoftware.com",
19
+ "bugs": {
20
+ "url": "https://github.com/storm-software/storm-ops/issues",
21
+ "email": "support@stormsoftware.com"
22
+ },
23
+ "repository": {
24
+ "type": "github",
25
+ "url": "https://github.com/storm-software/storm-ops.git",
26
+ "directory": "packages/markdownlint"
27
+ },
28
+ "license": "Apache-2.0",
29
+ "author": {
30
+ "name": "Storm Software",
31
+ "email": "contact@stormsoftware.com",
32
+ "url": "https://stormsoftware.com"
33
+ },
34
+ "type": "module",
35
+ "dependencies": {
36
+ "lodash": "^4.17.21"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ }
41
+ }
package/project.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "markdownlint",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "projectType": "library",
5
+ "sourceRoot": "packages/markdownlint/src",
6
+ "targets": {
7
+ "build": {
8
+ "executor": "@nx/esbuild:esbuild",
9
+ "outputs": ["{options.outputPath}"],
10
+ "options": {
11
+ "outputPath": "dist/packages/markdownlint",
12
+ "tsConfig": "packages/markdownlint/tsconfig.json",
13
+ "project": "packages/markdownlint/package.json",
14
+ "main": "packages/markdownlint/src/index.ts",
15
+ "defaultConfiguration": "production",
16
+ "deleteOutputPath": true,
17
+ "sourcemap": false,
18
+ "minify": false,
19
+ "skipTypeCheck": true,
20
+ "platform": "node",
21
+ "format": ["cjs"],
22
+ "esbuildOptions": {
23
+ "outExtension": {
24
+ ".js": ".js"
25
+ }
26
+ },
27
+ "assets": [
28
+ {
29
+ "input": "packages/markdownlint",
30
+ "glob": "README.md",
31
+ "output": "."
32
+ },
33
+ {
34
+ "input": "packages/markdownlint",
35
+ "glob": "CHANGELOG.md",
36
+ "output": "."
37
+ },
38
+ {
39
+ "input": "",
40
+ "glob": "LICENSE",
41
+ "output": "."
42
+ }
43
+ ]
44
+ },
45
+ "configurations": {
46
+ "production": {
47
+ "debug": false,
48
+ "verbose": false
49
+ },
50
+ "development": {
51
+ "debug": true,
52
+ "verbose": true
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }
package/src/index.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The markdownlint library used by Storm Software for building TypeScript applications.
3
+ *
4
+ * @remarks
5
+ * An opinionated collection of markdownlint rules used by Storm Software.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+
10
+ import _ from "lodash";
11
+ import accessibilityRules from "./style/accessibility.json";
12
+ import base from "./style/base.json";
13
+ import { rules } from "./rules";
14
+
15
+ const offByDefault = ["no-empty-alt-text"];
16
+
17
+ for (const rule of rules) {
18
+ const ruleName = rule.names[1];
19
+ base[ruleName] = offByDefault.includes(ruleName) ? false : true;
20
+ }
21
+
22
+ export const init = function init(defaultConfig) {
23
+ return _.defaultsDeep(defaultConfig, accessibilityRules, base);
24
+ };
25
+
26
+ export default [...rules];
@@ -0,0 +1,5 @@
1
+ import SS01 from "./no-default-alt-text";
2
+ import SS02 from "./no-generic-link-text";
3
+ import SS03 from "./no-empty-alt-text";
4
+
5
+ export const rules = [SS01, SS02, SS03];
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Examples:
3
+ * * "Screen Shot 2020-10-20 at 2 52 27 PM"
4
+ * * "Screenshot 2020-10-20 at 2 52 27 PM"
5
+ * * "Clean Shot 2020-10-20 @45x"
6
+ * * "Screencast from 23 02 2024 19 15 19]"
7
+ */
8
+ const defaultScreenshotRegex =
9
+ "(?:screen|clean) ?(?:shot|cast) \\d{4}-\\d{2}-\\d{2}[^'\"\\]]*";
10
+
11
+ const imageRegex = "image";
12
+ const combinedRegex = `(${[defaultScreenshotRegex, imageRegex].join("|")})`;
13
+
14
+ const markdownAltRegex = new RegExp(`!\\[${combinedRegex}\\]\\(.*\\)`, "gid");
15
+ const htmlAltRegex = new RegExp(`alt=["']${combinedRegex}["']`, "gid");
16
+
17
+ export default {
18
+ names: ["SS001", "no-default-alt-text"],
19
+ description: "Images should have meaningful alternative text (alt text)",
20
+ information: new URL(
21
+ "https://github.com/github/markdownlint-github/blob/main/docs/rules/GH001-no-default-alt-text.md"
22
+ ),
23
+ tags: ["accessibility", "images"],
24
+ function: function SS001(params, onError) {
25
+ const htmlTagsWithImages = params.parsers.markdownit.tokens.filter(
26
+ token => {
27
+ return (
28
+ (token.type === "html_block" && token.content.includes("<img")) ||
29
+ (token.type === "inline" &&
30
+ token.content.includes("<img") &&
31
+ token.children.some(child => child.type === "html_inline"))
32
+ );
33
+ }
34
+ );
35
+ const inlineImages = params.parsers.markdownit.tokens.filter(
36
+ token =>
37
+ token.type === "inline" &&
38
+ token.children.some(child => child.type === "image")
39
+ );
40
+
41
+ for (const token of [...htmlTagsWithImages, ...inlineImages]) {
42
+ const lineRange = token.map;
43
+ const lineNumber = token.lineNumber;
44
+ const lines = params.lines.slice(lineRange[0], lineRange[1]);
45
+ for (let i = 0; i < lines.length; i++) {
46
+ const line = lines[i];
47
+ let matches;
48
+ if (token.type === "inline") {
49
+ if (token.children.some(child => child.type === "html_inline")) {
50
+ matches = line.matchAll(htmlAltRegex);
51
+ } else {
52
+ matches = line.matchAll(markdownAltRegex);
53
+ }
54
+ } else {
55
+ matches = line.matchAll(htmlAltRegex);
56
+ }
57
+ for (const match of matches) {
58
+ const altText = match[1];
59
+ const [startIndex] = match.indices[1];
60
+ onError({
61
+ lineNumber: lineNumber + i,
62
+ range: [startIndex + 1, altText.length],
63
+ detail: `Flagged alt: ${altText}`
64
+ });
65
+ }
66
+ }
67
+ }
68
+ }
69
+ };
@@ -0,0 +1,48 @@
1
+ export default {
2
+ names: ["SS003", "no-empty-alt-text"],
3
+ description: "Please provide an alternative text for the image.",
4
+ information: new URL(
5
+ "https://github.com/github/markdownlint-github/blob/main/docs/rules/GH003-no-empty-alt-text.md"
6
+ ),
7
+ tags: ["accessibility", "images"],
8
+ function: function SS003(params, onError) {
9
+ const htmlTagsWithImages = params.parsers.markdownit.tokens.filter(
10
+ token => {
11
+ return (
12
+ (token.type === "html_block" && token.content.includes("<img")) ||
13
+ (token.type === "inline" &&
14
+ token.content.includes("<img") &&
15
+ token.children.some(child => child.type === "html_inline"))
16
+ );
17
+ }
18
+ );
19
+
20
+ const ImageRegex = new RegExp(/<img(.*?)>/, "gid");
21
+ const htmlEmptyAltRegex = new RegExp(/alt=['"]['"]/, "gid");
22
+ for (const token of htmlTagsWithImages) {
23
+ const lineRange = token.map;
24
+ const lineNumber = token.lineNumber;
25
+ const lines = params.lines.slice(lineRange[0], lineRange[1]);
26
+
27
+ for (const [i, line] of lines.entries()) {
28
+ const imageTags = line.matchAll(ImageRegex);
29
+
30
+ for (const imageTag of imageTags) {
31
+ const imageTagIndex = imageTag.indices[0][0];
32
+
33
+ const emptyAltMatches = [
34
+ ...imageTag[0].matchAll(htmlEmptyAltRegex)
35
+ ][0];
36
+ if (emptyAltMatches) {
37
+ const matchingContent = emptyAltMatches[0];
38
+ const startIndex = emptyAltMatches.indices[0][0];
39
+ onError({
40
+ lineNumber: lineNumber + i,
41
+ range: [imageTagIndex + startIndex + 1, matchingContent.length]
42
+ });
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+ };
@@ -0,0 +1,62 @@
1
+ function stripAndDowncaseText(text) {
2
+ return text
3
+ .toLowerCase()
4
+ .replace(/[.,/#!$%^&*;:{}=\-_`~()]/g, "")
5
+ .replace(/\s+/g, " ")
6
+ .trim();
7
+ }
8
+
9
+ const bannedLinkText = [
10
+ "read more",
11
+ "learn more",
12
+ "more",
13
+ "here",
14
+ "click here",
15
+ "link"
16
+ ];
17
+
18
+ export default {
19
+ names: ["SS002", "no-generic-link-text"],
20
+ description:
21
+ "Avoid using generic link text like `Learn more` or `Click here`",
22
+ information: new URL(
23
+ "https://github.com/github/markdownlint-github/blob/main/docs/rules/GH002-no-generic-link-text.md"
24
+ ),
25
+ tags: ["accessibility", "links"],
26
+ function: function SS002(params, onError) {
27
+ // markdown syntax
28
+ let bannedLinkTexts = bannedLinkText.concat(
29
+ params.config.additional_banned_texts || []
30
+ );
31
+ const exceptions = params.config.exceptions || [];
32
+ if (exceptions.length > 0) {
33
+ bannedLinkTexts = bannedLinkTexts.filter(
34
+ text => !exceptions.includes(text)
35
+ );
36
+ }
37
+ const inlineTokens = params.tokens.filter(t => t.type === "inline");
38
+ for (const token of inlineTokens) {
39
+ const { children } = token;
40
+ let inLink = false;
41
+ let linkText = "";
42
+
43
+ for (const child of children) {
44
+ const { content, type } = child;
45
+ if (type === "link_open") {
46
+ inLink = true;
47
+ linkText = "";
48
+ } else if (type === "link_close") {
49
+ inLink = false;
50
+ if (bannedLinkTexts.includes(stripAndDowncaseText(linkText))) {
51
+ onError({
52
+ lineNumber: child.lineNumber,
53
+ detail: `For link: ${linkText}`
54
+ });
55
+ }
56
+ } else if (inLink) {
57
+ linkText += content;
58
+ }
59
+ }
60
+ }
61
+ }
62
+ };
@@ -0,0 +1,14 @@
1
+ {
2
+ "no-alt-text": true,
3
+ "no-default-alt-text": true,
4
+ "no-duplicate-header": true,
5
+ "no-emphasis-as-header": true,
6
+ "no-generic-link-text": true,
7
+ "heading-increment": true,
8
+ "no-space-in-links": false,
9
+ "ol-prefix": "ordered",
10
+ "single-h1": true,
11
+ "ul-style": {
12
+ "style": "asterisk"
13
+ }
14
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "default": true,
3
+ "no-inline-html": false,
4
+ "no-bare-urls": false,
5
+ "no-alt-text": true,
6
+ "no-blanks-blockquote": false,
7
+ "fenced-code-language": true,
8
+ "heading-increment": true,
9
+ "single-h1": true,
10
+ "no-emphasis-as-header": true,
11
+ "first-line-heading": false
12
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "resolveJsonModule": true,
6
+ "noEmit": true
7
+ },
8
+ "files": [],
9
+ "include": ["src/**/*.ts", "src/**/*.js", "bin/**/*"],
10
+ "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
11
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "types": ["jest", "node"]
6
+ },
7
+ "include": [
8
+ "jest.config.ts",
9
+ "src/**/*.test.ts",
10
+ "src/**/*.spec.ts",
11
+ "src/**/*.d.ts"
12
+ ]
13
+ }