├── .github
├── CODEOWNERS
├── dependabot.yml
└── workflows
│ ├── accessibility-alt-text-bot.yml
│ ├── ci.yml
│ └── publish.yml
├── .gitignore
├── .markdownlint-cli2.mjs
├── .nvmrc
├── CHANGELOG.md
├── CODEOWNERS
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.txt
├── README.md
├── SECURITY.md
├── SUPPORT.md
├── docs
└── rules
│ ├── GH001-no-default-alt-text.md
│ ├── GH002-no-generic-link-text.md
│ └── GH003-no-empty-alt-text.md
├── eslint.config.js
├── index.js
├── jest.config.json
├── package-lock.json
├── package.json
├── src
├── helpers
│ └── strip-and-downcase-text.js
└── rules
│ ├── index.js
│ ├── no-default-alt-text.js
│ ├── no-empty-alt-text.js
│ └── no-generic-link-text.js
├── style
├── accessibility.js
└── base.js
└── test
├── accessibility-rules.test.js
├── example.md
├── no-default-alt-text.test.js
├── no-empty-alt-text.test.js
├── no-generic-link-text.test.js
├── strip-and-downcase-text.test.js
├── usage.test.js
└── utils
└── run-test.js
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @github/accessibility
2 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: npm
4 | directory: "/"
5 | schedule:
6 | interval: weekly
7 | groups:
8 | all-dependencies:
9 | patterns:
10 | - "*"
11 | update-types:
12 | - "minor"
13 | - "patch"
14 | open-pull-requests-limit: 99
15 | - package-ecosystem: github-actions
16 | directory: '/'
17 | schedule:
18 | interval: weekly
19 | open-pull-requests-limit: 99
20 | groups:
21 | all-dependencies:
22 | patterns:
23 | - "*"
24 | update-types:
25 | - "minor"
26 | - "patch"
--------------------------------------------------------------------------------
/.github/workflows/accessibility-alt-text-bot.yml:
--------------------------------------------------------------------------------
1 | name: Accessibility-alt-text-bot
2 | on:
3 | issues:
4 | types: [opened, edited]
5 | pull_request:
6 | types: [opened, edited]
7 | issue_comment:
8 | types: [created, edited, deleted]
9 | discussion:
10 | types: [created, edited]
11 | discussion_comment:
12 | types: [created, edited, deleted]
13 |
14 | permissions:
15 | issues: write
16 | pull-requests: write
17 | discussions: write
18 |
19 | jobs:
20 | accessibility_alt_text_bot:
21 | name: Check alt text is set on issue or pull requests
22 | runs-on: ubuntu-latest
23 | if: ${{ github.event.issue || github.event.pull_request || github.event.discussion }}
24 | steps:
25 | - name: Get action 'github/accessibility-alt-text-bot'
26 | uses: github/accessibility-alt-text-bot@v1.7.1
27 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: Run linter and tests
2 | permissions:
3 | contents: read
4 | pull-requests: write
5 | on:
6 | push:
7 | branches:
8 | - main
9 | pull_request:
10 | jobs:
11 | lint:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v4
15 | - uses: actions/setup-node@v4
16 | with:
17 | node-version: 22
18 | - run: npm install
19 | - run: npm test
20 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish
2 | permissions:
3 | contents: read
4 | pull-requests: write
5 | id-token: write
6 | on:
7 | release:
8 | types: [created]
9 |
10 | jobs:
11 | publish-npm:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v4
15 | - uses: actions/setup-node@v4
16 | with:
17 | node-version: 22
18 | registry-url: https://registry.npmjs.org/
19 | cache: npm
20 | - run: npm ci
21 | - run: npm test
22 | - run: |
23 | echo "Publishing $TAG_NAME"
24 | npm version ${TAG_NAME} --git-tag-version=false
25 | env:
26 | TAG_NAME: ${{github.event.release.tag_name}}
27 | - run: npm whoami; npm --ignore-scripts publish --provenance
28 | env:
29 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
--------------------------------------------------------------------------------
/.markdownlint-cli2.mjs:
--------------------------------------------------------------------------------
1 | import { init } from "./index.js";
2 |
3 | const configOptions = await init({
4 | default: false,
5 | "heading-increment": true,
6 | "no-alt-text": true,
7 | "single-h1": true,
8 | "no-emphasis-as-heading": true,
9 | "first-line-heading": true,
10 | });
11 | const options = {
12 | config: configOptions,
13 | customRules: ["./index.js"],
14 | };
15 | export default options;
16 |
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | 18
2 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## 0.2.0
4 |
5 | * BREAKING change: Convert to ECMAScript modules (ESM)
6 |
7 | ## 0.1.0
8 |
9 | * Initial release
10 |
--------------------------------------------------------------------------------
/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @github/accessibility-reviewers
2 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, gender identity and expression, level of experience,
9 | nationality, personal appearance, race, religion, or sexual identity and
10 | orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at opensource@github.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at [http://contributor-covenant.org/version/1/4][version]
72 |
73 | [homepage]: http://contributor-covenant.org
74 | [version]: http://contributor-covenant.org/version/1/4/
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing Guide
2 |
3 | Thank you for your interest in contributing.
4 |
5 | ## Developing
6 |
7 | Depending on your needs, you may have one of two development paths:
8 |
9 | * via integrating with an existing usage (ideal for modifying the interface of our rules)
10 | * via unit testing (ideal for adding a new rule)
11 |
12 | For that reason we've included two paths to develop. Feel free to use either, or both.
13 |
14 | ### Behavioral troubleshooting
15 |
16 | It may be useful to work on this in tandem with a codebase that uses the rules. In that case, we encourage improving local development experience by leveraging `npm link` functionality:
17 |
18 | 1. In this repository on your machine, create the symlink to your local development directory
19 |
20 | ```bash
21 | npm link
22 | npm ls @github/markdownlint-github # should show a symlink
23 | ```
24 |
25 | 2. In the codebase you want to test against, replace the package in your `node_modules` folder with the symlink reference
26 |
27 | ```bash
28 | cd ../your-codebase
29 | npm link @github/markdownlint-github
30 | ```
31 |
32 | If you go to the `node_modules` directory in your codebase and try to navigate into the package, you'll notice that whatever changes you make in your local development directory will be reflected in the codebase.
33 |
34 | 3. Reset symlinks at any time by reversing the steps via `npm unlink`.
35 | * in your codebase: `npm unlink @github/markdownlint-github`
36 | * in this directory: `npm unlink`
37 |
38 | ### Unit and Interface Testing
39 |
40 | We use `jest` tests as well, which should be an equally comfortable development experience. Refer to existing test files for any patterns you may find useful.
41 |
42 | ## Publishing
43 |
44 | The [publish.yml workflow](https://github.com/github/markdownlint-github/actions/workflows/publish.yml) will automatically publish a new release on npm upon creating a [new GitHub release](https://github.com/github/markdownlint-github/releases).
45 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright GitHub
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Markdownlint-github
2 |
3 | This repository provides GitHub's recommended [`markdownlint`](https://github.com/DavidAnson/markdownlint) configurations, and additional rules for use on GitHub open source and internal projects.
4 |
5 | ## Opinions
6 |
7 | In addition to defaults defined by `markdownlint`, we use this repository to enforce rules not defined by default, including our own custom rules.
8 |
9 | See opinions codified in [index.js](./index.js).
10 |
11 | ## Rules
12 |
13 | The following are custom rules defined in this plugin.
14 |
15 | * [**GH001** _no-default-alt-text_](./docs/rules/GH001-no-default-alt-text.md)
16 | * [**GH002** _no-generic-link-text_](./docs/rules/GH002-no-generic-link-text.md)
17 | * [**GH003** _no-empty-alt-text_](./docs/rules/GH003-no-empty-alt-text.md)
18 |
19 | See [`markdownlint` rules](https://github.com/DavidAnson/markdownlint#rules--aliases) for documentation on rules pulled in from `markdownlint`.
20 |
21 | ## Usage
22 |
23 | **Important**: We support the use of `markdownlint` through [`markdownlint-cli2`](https://github.com/DavidAnson/markdownlint-cli2) instead of `markdownlint-cli` for compatibility with the [`vscode-markdownlint`](https://github.com/DavidAnson/vscode-markdownlint) plugin.
24 |
25 | 1. Create a `.markdownlint-cli2.mjs` file in the root of your repository.
26 |
27 | ```bash
28 | touch .markdownlint-cli2.mjs
29 | ```
30 |
31 | 2. Install packages.
32 |
33 | ```bash
34 | npm install -D markdownlint-cli2 # if updating existing package, check for updates
35 | npm install -D @github/markdownlint-github [--@github:registry=https://registry.npmjs.org]
36 | npm install -D markdownlint-cli2-formatter-pretty
37 | ```
38 |
39 | 3. Add/modify your linting script in `package.json`.
40 |
41 | ```json
42 | "scripts": {
43 | "lint:markdown": "markdownlint-cli2 \"**/*.{md,mdx}\" \"!node_modules\""
44 | }
45 | ```
46 |
47 | 4. Edit `.markdownlint-cli2.mjs` file to suit your needs. Start with
48 |
49 | ```js
50 | import configOptions, {init} from "@github/markdownlint-github"
51 | const options = {
52 | config: init(),
53 | customRules: ["@github/markdownlint-github"],
54 | outputFormatters: [
55 | [ "markdownlint-cli2-formatter-pretty", { "appendLink": true } ] // ensures the error message includes a link to the rule documentation
56 | ]
57 | }
58 | export default options
59 | ```
60 |
61 | Or, you can also pass in configuration options that you wish to override the default. Read more at [Customizing configurations](#customizing-configurations).
62 | This looks like:
63 |
64 | ```js
65 | import configOptions, {init} from "@github/markdownlint-github"
66 | const overriddenOptions = init({
67 | 'fenced-code-language': false, // Custom overrides
68 | })
69 | const options = {
70 | config: overriddenOptions,
71 | customRules: ["@github/markdownlint-github"],
72 | outputFormatters: [
73 | [ "markdownlint-cli2-formatter-pretty", { "appendLink": true } ]
74 | ]
75 | }
76 | export default options
77 | ```
78 |
79 | 5. Install the [`vscode-markdownlint`](https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint) plugin to ensure `markdownlint` violations are surfaced in the file. This plugin should flag rules based off your `.markdownlint-cli2.mjs` configuration. When you make edits to your configuration, you will need to reload the VSCode window (`Ctrl+Shift+P` -> `Reload Window`) to ensure the extension syncs. If your project runs on Codespaces, consider adding this extension to your `.devcontainer/devcontainer.json` so that this extension is installed to new Codespaces by default.
80 |
81 | ### Customizing configurations
82 |
83 | You may determine that the defaults set by this plugin are not suitable for your project.
84 |
85 | This plugin will pull in the the defaults defined by `markdownlint`, several of which pertain to stylistic practices. You may choose to disable these rules if you determine it doesn't provide value for your project.
86 |
87 | However, others of these rules should **NOT** be disabled because they encourage best accessibility practices. Disabling these rules will negatively impact accessibility. These rules are defined in [accessibility.json](./style/accessibility.json).
88 |
89 | To review configurations supported by `markdownlint`, see [`markdownlint-cli2` configuration](https://github.com/DavidAnson/markdownlint-cli2#configuration).
90 |
91 | ### Advanced: Adding custom rules in your codebase
92 |
93 | You may write custom rules within your repository. Follow the [custom rules guide in `markdownlint`](https://github.com/DavidAnson/markdownlint/blob/main/doc/CustomRules.md) to write your rule.
94 |
95 | The rule will need to be enabled in the configuration. For instance, if you introduce `some-rule.js` with the name "some-rule", you must set the path of the custom rule in the `.markdownlint-cli2.mjs` file:
96 |
97 | ```js
98 | import configOptions, {init} from "@github/markdownlint-github"
99 | const options = init({
100 | "some-rule": true,
101 | customRules: ["@github/markdownlint-github", "some-rule.js"],
102 | })
103 | export default options
104 | ```
105 |
106 | See [`markdownlint-cli2` configuration](https://github.com/DavidAnson/markdownlint-cli2#configuration).
107 |
108 | Consider upstreaming any rules you find useful as proposals to this repository.
109 |
110 | ## License
111 |
112 | This project is licensed under the terms of the MIT open source license. Please
113 | refer to [the MIT license](./LICENSE.txt) for the full terms.
114 |
115 | ## Maintainers
116 |
117 | See [CODEOWNERS](./CODEOWNERS).
118 |
119 | ## Contributing
120 |
121 | Please read [Contributing Guide](./CONTRIBUTING.md) for more information.
122 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security
2 |
3 | Thanks for helping make GitHub safe for everyone.
4 |
5 | GitHub takes the security of our software products and services seriously, including all of the open source code repositories managed through our GitHub organizations, such as [GitHub](https://github.com/GitHub).
6 |
7 | Even though [open source repositories are outside of the scope of our bug bounty program](https://bounty.github.com/index.html#scope) and therefore not eligible for bounty rewards, we will ensure that your finding gets passed along to the appropriate maintainers for remediation.
8 |
9 | ## Reporting Security Issues
10 |
11 | If you believe you have found a security vulnerability in any GitHub-owned repository, please report it to us through coordinated disclosure.
12 |
13 | **Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
14 |
15 | Instead, please send an email to opensource-security[@]github.com.
16 |
17 | Please include as much of the information listed below as you can to help us better understand and resolve the issue:
18 |
19 | * The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting)
20 | * Full paths of source file(s) related to the manifestation of the issue
21 | * The location of the affected source code (tag/branch/commit or direct URL)
22 | * Any special configuration required to reproduce the issue
23 | * Step-by-step instructions to reproduce the issue
24 | * Proof-of-concept or exploit code (if possible)
25 | * Impact of the issue, including how an attacker might exploit the issue
26 |
27 | This information will help us triage your report more quickly.
28 |
29 | ## Policy
30 |
31 | See [GitHub's Safe Harbor Policy](https://docs.github.com/en/github/site-policy/github-bug-bounty-program-legal-safe-harbor#1-safe-harbor-terms)
--------------------------------------------------------------------------------
/SUPPORT.md:
--------------------------------------------------------------------------------
1 | # Support
2 |
3 | ## How to file issues and get help
4 |
5 | This project uses GitHub issues to track bugs and feature requests. Please search the existing issues before filing new issues to avoid duplicates. For new issues, file your bug or feature request as a new issue.
6 |
7 | For help or questions about using this project, please file an issue.
8 |
9 | **markdownlint-github** is under active development and maintained by GitHub staff **AND THE COMMUNITY**. We will do our best to respond to support, feature requests, and community questions in a timely manner.
10 |
11 | ## GitHub Support Policy
12 |
13 | Support for this project is limited to the resources listed above.
--------------------------------------------------------------------------------
/docs/rules/GH001-no-default-alt-text.md:
--------------------------------------------------------------------------------
1 | # GH001 No default alt text
2 |
3 | ## Rule details
4 |
5 | Images should not use the macOS default screenshot filename as alternate text (alt text) which does not convey any meaningful information.
6 |
7 | Alternative text should concisely describe what is conveyed in the image. If the image is decorative, the alternative text should be set to an empty string (`alt=""`).
8 |
9 | Learn more at [Primer: Alternative text for images](https://primer.style/design/accessibility/alternative-text-for-images).
10 |
11 | ## Examples
12 |
13 | ### Incorrect 👎
14 |
15 | ```md
16 | 
17 | ```
18 |
19 | ```md
20 |
21 | ```
22 |
23 | ### Correct 👍
24 |
25 | ```md
26 |
27 |
28 | 
29 | ```
30 |
31 | ```md
32 |
33 | ```
34 |
35 | ```md
36 |
37 | ```
38 |
39 |
--------------------------------------------------------------------------------
/docs/rules/GH002-no-generic-link-text.md:
--------------------------------------------------------------------------------
1 | # GH002 No generic link text
2 |
3 | ## Rule details
4 |
5 | Avoid setting generic link text like, "Click here", "Read more", and "Learn more" which do not make sense when read out of context.
6 |
7 | Screen reader users often tab through links on a page to quickly find content without needing to listen to the full page. When link text does not clearly describe the actual linked content, it becomes difficult to quickly identify whether it's worth following the link.
8 |
9 | Ensure that your link text is descriptive and the purpose of the link is clear even when read without the context provided by surrounding text.
10 |
11 | Learn more about how to write descriptive link text at [Access Guide: Write descriptive link text](https://www.accessguide.io/guide/descriptive-link-text).
12 |
13 | **Note**: For now, this rule only flags inline markdown implementation of links given the complexities of determining the accessible name of an HTML anchor tag,
14 |
15 | ## Configuration
16 |
17 | You can configure additional link texts to flag by setting the rule configuration like the following:
18 |
19 | ```.js
20 | {
21 | "no-generic-link-text": {
22 | "additional_banned_texts": ["Something", "Go here"]
23 | }
24 | }
25 | ```
26 | ## Examples
27 |
28 | ### Incorrect 👎
29 |
30 | ```md
31 | Go [here](https://github.com/)
32 | ```
33 |
34 | ```md
35 | [Learn more](https://docs.github.com)
36 | ```
37 |
38 | ```md
39 | [Click here](https://github.com/new) to create a new repository.
40 | ```
41 |
42 | ### Correct 👍
43 |
44 | ```md
45 | [GitHub](https://github.com/)
46 | ```
47 |
48 | ```md
49 | [GitHub Docs](https://docs.github.com)
50 | ```
51 |
52 | ```md
53 | [Create a new repository](https://github.com/new)
54 | ```
--------------------------------------------------------------------------------
/docs/rules/GH003-no-empty-alt-text.md:
--------------------------------------------------------------------------------
1 | # GH003 No Empty Alt Text
2 |
3 | ## Rule details
4 |
5 | ⚠️ This rule is _off_ by default and is only applicable for GitHub rendered markdown.
6 |
7 | Currently, all images on github.com are automatically wrapped in an anchor tag.
8 |
9 | As a result, images that are intentionally marked as decorative (via `alt=""`) end up rendering as a link without an accessible name. This is confusing and inaccessible for assistive technology users.
10 |
11 | This rule can be enabled to enforce that the alt attribute is always set to descriptive text.
12 |
13 | This rule should be removed once this behavior is updated on GitHub's UI.
14 |
15 | ## Examples
16 |
17 | ### Incorrect 👎
18 |
19 | ```html
20 |
21 | ```
22 |
23 | ### Correct 👍
24 |
25 | ```html
26 |
27 | ```
28 |
--------------------------------------------------------------------------------
/eslint.config.js:
--------------------------------------------------------------------------------
1 | import github from "eslint-plugin-github";
2 | import globals from "globals";
3 |
4 | export default [
5 | github.getFlatConfigs().recommended,
6 | {
7 | languageOptions: {
8 | ecmaVersion: 13,
9 | globals: {
10 | ...globals.es6,
11 | ...globals.node,
12 | ...globals.jest,
13 | },
14 | },
15 | files: ["**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}"],
16 | rules: {
17 | "github/filenames-match-regex": "off",
18 | "i18n-text/no-en": "off",
19 | "import/extensions": ["error", { js: "ignorePackages" }],
20 | "import/no-unresolved": [
21 | "error",
22 | {
23 | ignore: ["^markdownlint/.+"],
24 | },
25 | ],
26 | },
27 | },
28 | ];
29 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import _ from "lodash-es";
2 | import { githubMarkdownLint } from "./src/rules/index.js";
3 |
4 | import accessibilityRules from "./style/accessibility.js";
5 | import baseRules from "./style/base.js";
6 |
7 | const offByDefault = ["no-empty-alt-text"];
8 |
9 | export function init(consumerConfig) {
10 | const base = { ...baseRules };
11 |
12 | for (const rule of githubMarkdownLint) {
13 | const ruleName = rule.names[1];
14 | base[ruleName] = offByDefault.includes(ruleName) ? false : true;
15 | }
16 |
17 | return _.defaultsDeep(consumerConfig, accessibilityRules, base);
18 | }
19 |
20 | export default githubMarkdownLint;
21 |
--------------------------------------------------------------------------------
/jest.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "transform": {
3 | }
4 | }
5 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@github/markdownlint-github",
3 | "version": "0.2.0",
4 | "description": "An opinionated collection of markdownlint rules used by GitHub.",
5 | "type": "module",
6 | "exports": "./index.js",
7 | "engines": {
8 | "node": ">=18"
9 | },
10 | "directories": {
11 | "test": "test"
12 | },
13 | "scripts": {
14 | "publish": "npm publish --access public --@github:registry=https://registry.npmjs.org",
15 | "test": "npm run lint && NODE_OPTIONS=--experimental-vm-modules jest",
16 | "lint": "markdownlint-cli2 \"**/*.{md,mdx}\" \"!node_modules\" \"!docs/rules\" \"!test/example.md\" && eslint .",
17 | "lint:fix": "npm run lint -- --fix"
18 | },
19 | "dependencies": {
20 | "lodash-es": "^4.17.15"
21 | },
22 | "devDependencies": {
23 | "eslint": "^9.16.0",
24 | "globals": "^16.0.0",
25 | "eslint-plugin-github": "^6.0.0",
26 | "jest": "^29.5.0",
27 | "markdownlint": "^0.37.3",
28 | "markdownlint-cli2": "^0.17.1"
29 | },
30 | "repository": {
31 | "type": "git",
32 | "url": "git+https://github.com/github/markdownlint-github.git"
33 | },
34 | "keywords": [
35 | "markdownlint-rule"
36 | ],
37 | "author": "Andri Alexandrou ",
38 | "license": "ISC",
39 | "bugs": {
40 | "url": "https://github.com/github/markdownlint-github/issues"
41 | },
42 | "homepage": "https://github.com/github/markdownlint-github#readme"
43 | }
44 |
--------------------------------------------------------------------------------
/src/helpers/strip-and-downcase-text.js:
--------------------------------------------------------------------------------
1 | /* Downcase and strip extra whitespaces and punctuation */
2 | export function stripAndDowncaseText(text) {
3 | return text
4 | .toLowerCase()
5 | .replace(/[.,/#!$%^&*;:{}=\-_`~()]/g, "")
6 | .replace(/\s+/g, " ")
7 | .trim();
8 | }
9 |
--------------------------------------------------------------------------------
/src/rules/index.js:
--------------------------------------------------------------------------------
1 | import { noEmptyStringAltRule } from "./no-empty-alt-text.js";
2 | import { noGenericLinkTextRule } from "./no-generic-link-text.js";
3 | import { altTextRule } from "./no-default-alt-text.js";
4 |
5 | export const githubMarkdownLint = [
6 | altTextRule,
7 | noGenericLinkTextRule,
8 | noEmptyStringAltRule,
9 | ];
10 |
--------------------------------------------------------------------------------
/src/rules/no-default-alt-text.js:
--------------------------------------------------------------------------------
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 const altTextRule = {
18 | names: ["GH001", "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 GH001(params, onError) {
25 | const htmlTagsWithImages = params.parsers.markdownit.tokens.filter(
26 | (token) => {
27 | return (
28 | (token.type === "html_block" && token.content.includes("
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 | };
70 |
--------------------------------------------------------------------------------
/src/rules/no-empty-alt-text.js:
--------------------------------------------------------------------------------
1 | export const noEmptyStringAltRule = {
2 | names: ["GH003", "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 GH003(params, onError) {
9 | const htmlTagsWithImages = params.parsers.markdownit.tokens.filter(
10 | (token) => {
11 | return (
12 | (token.type === "html_block" && token.content.includes("
child.type === "html_inline"))
16 | );
17 | },
18 | );
19 |
20 | const ImageRegex = new RegExp(/
/, "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 | };
49 |
--------------------------------------------------------------------------------
/src/rules/no-generic-link-text.js:
--------------------------------------------------------------------------------
1 | import { stripAndDowncaseText } from "../helpers/strip-and-downcase-text.js";
2 |
3 | const bannedLinkText = [
4 | "read more",
5 | "learn more",
6 | "more",
7 | "here",
8 | "click here",
9 | "link",
10 | ];
11 |
12 | export const noGenericLinkTextRule = {
13 | names: ["GH002", "no-generic-link-text"],
14 | description:
15 | "Avoid using generic link text like `Learn more` or `Click here`",
16 | information: new URL(
17 | "https://github.com/github/markdownlint-github/blob/main/docs/rules/GH002-no-generic-link-text.md",
18 | ),
19 | tags: ["accessibility", "links"],
20 | function: function GH002(params, onError) {
21 | // markdown syntax
22 | let bannedLinkTexts = bannedLinkText.concat(
23 | params.config.additional_banned_texts || [],
24 | );
25 | const exceptions = params.config.exceptions || [];
26 | if (exceptions.length > 0) {
27 | bannedLinkTexts = bannedLinkTexts.filter(
28 | (text) => !exceptions.includes(text),
29 | );
30 | }
31 | const inlineTokens = params.tokens.filter((t) => t.type === "inline");
32 | for (const token of inlineTokens) {
33 | const { children } = token;
34 | let inLink = false;
35 | let linkText = "";
36 |
37 | for (const child of children) {
38 | const { content, type } = child;
39 | if (type === "link_open") {
40 | inLink = true;
41 | linkText = "";
42 | } else if (type === "link_close") {
43 | inLink = false;
44 | if (bannedLinkTexts.includes(stripAndDowncaseText(linkText))) {
45 | onError({
46 | lineNumber: child.lineNumber,
47 | detail: `For link: ${linkText}`,
48 | });
49 | }
50 | } else if (inLink) {
51 | linkText += content;
52 | }
53 | }
54 | }
55 | },
56 | };
57 |
--------------------------------------------------------------------------------
/style/accessibility.js:
--------------------------------------------------------------------------------
1 | export default {
2 | "no-alt-text": true,
3 | "no-default-alt-text": true,
4 | "no-duplicate-heading": true,
5 | "no-emphasis-as-heading": 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 | };
15 |
--------------------------------------------------------------------------------
/style/base.js:
--------------------------------------------------------------------------------
1 | export default {
2 | default: true,
3 | "no-inline-html": false,
4 | "no-bare-urls": false,
5 | "no-blanks-blockquote": false,
6 | "fenced-code-language": true,
7 | };
8 |
--------------------------------------------------------------------------------
/test/accessibility-rules.test.js:
--------------------------------------------------------------------------------
1 | import { lint } from "markdownlint/async";
2 | import githubMarkdownLint from "../index.js";
3 | import accessibilityRules from "../style/accessibility.js";
4 |
5 | const exampleFileName = "./test/example.md";
6 |
7 | describe("when A11y rules applied", () => {
8 | test("fails expected rules", async () => {
9 | const options = {
10 | config: {
11 | default: false,
12 | ...accessibilityRules,
13 | },
14 | files: [exampleFileName],
15 | customRules: githubMarkdownLint,
16 | };
17 |
18 | const result = await new Promise((resolve, reject) => {
19 | lint(options, (err, res) => {
20 | if (err) reject(err);
21 | resolve(res);
22 | });
23 | });
24 |
25 | const failuresForExampleFile = result[exampleFileName];
26 | const failureNames = failuresForExampleFile
27 | .map((failure) => failure.ruleNames)
28 | .flat();
29 |
30 | expect(failuresForExampleFile).toHaveLength(3);
31 | expect(failureNames).toContain("no-default-alt-text");
32 | });
33 | });
34 |
--------------------------------------------------------------------------------
/test/example.md:
--------------------------------------------------------------------------------
1 | # Example Violations
2 |
3 | 
4 |
5 | ![image]()
--------------------------------------------------------------------------------
/test/no-default-alt-text.test.js:
--------------------------------------------------------------------------------
1 | import { altTextRule } from "../src/rules/no-default-alt-text";
2 | import { runTest } from "./utils/run-test";
3 |
4 | describe("GH001: No Default Alt Text", () => {
5 | describe("successes", () => {
6 | test("inline", async () => {
7 | const strings = [
8 | "``````",
9 | "``",
10 | "",
11 | ];
12 |
13 | const results = await runTest(strings, altTextRule);
14 | expect(results.length).toBe(0);
15 | });
16 | test("html image", async () => {
17 | const strings = [
18 | '
',
19 | ];
20 |
21 | const results = await runTest(strings, altTextRule);
22 | expect(results.length).toBe(0);
23 | });
24 | });
25 | describe("failures", () => {
26 | test("markdown example", async () => {
27 | const strings = [
28 | "",
29 | "",
30 | "",
31 | "",
32 | "",
33 | "",
34 | "",
35 | "",
36 | ];
37 |
38 | const results = await runTest(strings, altTextRule);
39 |
40 | const failedRules = results
41 | .map((result) => result.ruleNames)
42 | .flat()
43 | .filter((name) => !name.includes("GH"));
44 |
45 | expect(failedRules).toHaveLength(7);
46 | for (const rule of failedRules) {
47 | expect(rule).toBe("no-default-alt-text");
48 | }
49 | });
50 |
51 | test("HTML example", async () => {
52 | const strings = [
53 | '
',
54 | '
',
55 | '
',
56 | '
',
57 | '
',
58 | '
',
59 | '
',
60 | '
',
61 | ];
62 |
63 | const results = await runTest(strings, altTextRule);
64 |
65 | const failedRules = results
66 | .map((result) => result.ruleNames)
67 | .flat()
68 | .filter((name) => !name.includes("GH"));
69 |
70 | expect(failedRules).toHaveLength(7);
71 | for (const rule of failedRules) {
72 | expect(rule).toBe("no-default-alt-text");
73 | }
74 | });
75 |
76 | test("flags multiple consecutive inline images", async () => {
77 | const strings = ['![image]()
'];
78 | const results = await runTest(strings, altTextRule);
79 | expect(results).toHaveLength(2);
80 |
81 | expect(results[0].errorRange).toEqual([11, 5]);
82 | expect(results[0].errorDetail).toEqual("Flagged alt: image");
83 | expect(results[1].errorRange).toEqual([28, 5]);
84 | expect(results[1].errorDetail).toEqual("Flagged alt: Image");
85 | });
86 |
87 | test("error message", async () => {
88 | const strings = [
89 | "",
90 | '
',
91 | ];
92 |
93 | const results = await runTest(strings, altTextRule);
94 |
95 | expect(results[0].ruleDescription).toMatch(
96 | "Images should have meaningful alternative text (alt text)",
97 | );
98 | expect(results[0].errorRange).toEqual([3, 36]);
99 | expect(results[1].ruleDescription).toMatch(
100 | "Images should have meaningful alternative text (alt text)",
101 | );
102 | expect(results[1].errorRange).toEqual([11, 36]);
103 | });
104 | });
105 | });
106 |
--------------------------------------------------------------------------------
/test/no-empty-alt-text.test.js:
--------------------------------------------------------------------------------
1 | import { noEmptyStringAltRule } from "../src/rules/no-empty-alt-text";
2 | import { runTest } from "./utils/run-test";
3 |
4 | describe("GH003: No Empty Alt Text", () => {
5 | describe("successes", () => {
6 | test("html image", async () => {
7 | const strings = [
8 | '
',
9 | "`
`", // code block
10 | ];
11 |
12 | const results = await runTest(strings, noEmptyStringAltRule);
13 | expect(results).toHaveLength(0);
14 | });
15 | });
16 | describe("failures", () => {
17 | test("HTML example", async () => {
18 | const strings = [
19 | '
',
20 | "
",
21 | '
',
22 | ];
23 |
24 | const results = await runTest(strings, noEmptyStringAltRule);
25 | const failedRules = results
26 | .map((result) => result.ruleNames)
27 | .flat()
28 | .filter((name) => !name.includes("GH"));
29 |
30 | expect(failedRules).toHaveLength(4);
31 | for (const rule of failedRules) {
32 | expect(rule).toBe("no-empty-alt-text");
33 | }
34 | });
35 |
36 | test("error message", async () => {
37 | const strings = [
38 | '
',
39 | '
',
40 | ];
41 |
42 | const results = await runTest(strings, noEmptyStringAltRule);
43 |
44 | expect(results[0].ruleDescription).toMatch(
45 | "Please provide an alternative text for the image.",
46 | );
47 | expect(results[0].errorRange).toEqual([6, 6]);
48 |
49 | expect(results[1].ruleDescription).toMatch(
50 | "Please provide an alternative text for the image.",
51 | );
52 | expect(results[1].errorRange).toEqual([20, 6]);
53 | expect(results[2].ruleDescription).toMatch(
54 | "Please provide an alternative text for the image.",
55 | );
56 | expect(results[2].errorRange).toEqual([49, 6]);
57 | });
58 | });
59 | });
60 |
--------------------------------------------------------------------------------
/test/no-generic-link-text.test.js:
--------------------------------------------------------------------------------
1 | import { noGenericLinkTextRule } from "../src/rules/no-generic-link-text";
2 | import { runTest } from "./utils/run-test";
3 |
4 | describe("GH002: No Generic Link Text", () => {
5 | describe("successes", () => {
6 | test("inline", async () => {
7 | const strings = [
8 | "[GitHub](https://www.github.com)",
9 | "[Read more about GitHub](https://www.github.com/about)",
10 | "[](www.github.com)",
11 | "",
12 | `
13 | ## Hello
14 | I am not a link, and unrelated.
15 | 
16 | `,
17 | ];
18 |
19 | const results = await runTest(strings, noGenericLinkTextRule);
20 | expect(results.length).toBe(0);
21 | });
22 | });
23 | describe("failures", () => {
24 | test("inline", async () => {
25 | const strings = [
26 | "[Click here](www.github.com)",
27 | "[here](www.github.com)",
28 | "Please [read more](www.github.com)",
29 | "[more](www.github.com)",
30 | "[link](www.github.com)",
31 | "You may [learn more](www.github.com) at GitHub",
32 | "[learn more.](www.github.com)",
33 | "[click here!](www.github.com)",
34 | ];
35 |
36 | const results = await runTest(strings, noGenericLinkTextRule);
37 |
38 | const failedRules = results
39 | .map((result) => result.ruleNames)
40 | .flat()
41 | .filter((name) => !name.includes("GH"));
42 |
43 | expect(failedRules).toHaveLength(8);
44 | for (const rule of failedRules) {
45 | expect(rule).toBe("no-generic-link-text");
46 | }
47 | });
48 |
49 | test("error message", async () => {
50 | const strings = ["[Click here](www.github.com)"];
51 |
52 | const results = await runTest(strings, noGenericLinkTextRule);
53 |
54 | expect(results[0].ruleDescription).toMatch(
55 | /Avoid using generic link text like `Learn more` or `Click here`/,
56 | );
57 | expect(results[0].errorDetail).toBe("For link: Click here");
58 | });
59 |
60 | test("additional words can be configured", async () => {
61 | const results = await runTest(
62 | ["[something](www.github.com)"],
63 | noGenericLinkTextRule,
64 | // eslint-disable-next-line camelcase
65 | { additional_banned_texts: ["something"] },
66 | );
67 |
68 | const failedRules = results
69 | .map((result) => result.ruleNames)
70 | .flat()
71 | .filter((name) => !name.includes("GH"));
72 |
73 | expect(failedRules).toHaveLength(1);
74 | });
75 |
76 | test("exceptions can be configured", async () => {
77 | const results = await runTest(
78 | ["[Link](primer.style/components/Link)"],
79 | noGenericLinkTextRule,
80 | { exceptions: ["link"] },
81 | );
82 |
83 | for (const result of results) {
84 | expect(result).not.toBeDefined();
85 | }
86 | });
87 | });
88 | });
89 |
--------------------------------------------------------------------------------
/test/strip-and-downcase-text.test.js:
--------------------------------------------------------------------------------
1 | import { stripAndDowncaseText } from "../src/helpers/strip-and-downcase-text";
2 |
3 | describe("stripAndDowncaseText", () => {
4 | test("strips extra whitespace", () => {
5 | expect(stripAndDowncaseText(" read more ")).toBe("read more");
6 | expect(stripAndDowncaseText(" learn ")).toBe("learn");
7 | });
8 |
9 | test("strips punctuation", () => {
10 | expect(stripAndDowncaseText("learn more!!!!")).toBe("learn more");
11 | expect(stripAndDowncaseText("I like dogs...")).toBe("i like dogs");
12 | });
13 |
14 | test("downcases text", () => {
15 | expect(stripAndDowncaseText("HeRe")).toBe("here");
16 | expect(stripAndDowncaseText("CLICK HERE")).toBe("click here");
17 | });
18 | });
19 |
--------------------------------------------------------------------------------
/test/usage.test.js:
--------------------------------------------------------------------------------
1 | import { init } from "../index.js";
2 | import { githubMarkdownLint } from "../src/rules/index.js";
3 |
4 | describe("usage", () => {
5 | describe("default export", () => {
6 | test("custom rules on default export", () => {
7 | const rules = githubMarkdownLint;
8 | expect(rules).toHaveLength(3);
9 |
10 | expect(rules[0].names).toEqual(["GH001", "no-default-alt-text"]);
11 | expect(rules[1].names).toEqual(["GH002", "no-generic-link-text"]);
12 | expect(rules[2].names).toEqual(["GH003", "no-empty-alt-text"]);
13 | });
14 | });
15 | describe("init method", () => {
16 | test("default options returned with no arguments provided", async () => {
17 | const options = await init();
18 | expect(options).toEqual({
19 | "no-duplicate-heading": true,
20 | "ol-prefix": "ordered",
21 | "no-space-in-links": false,
22 | "single-h1": true,
23 | "no-emphasis-as-heading": true,
24 | "no-empty-alt-text": false,
25 | "heading-increment": true,
26 | "no-generic-link-text": true,
27 | "ul-style": {
28 | style: "asterisk",
29 | },
30 | default: true,
31 | "no-inline-html": false,
32 | "no-bare-urls": false,
33 | "no-blanks-blockquote": false,
34 | "fenced-code-language": true,
35 | "no-default-alt-text": true,
36 | "no-alt-text": true,
37 | });
38 | });
39 |
40 | test("arguments override default configuration", async () => {
41 | const defaultOptions = await init();
42 |
43 | const toTestOptions = Object.keys(defaultOptions).slice(0, 3);
44 |
45 | // create a consumer config that is the opposite of the default config
46 | const originalConfig = {};
47 | const consumerConfig = {};
48 | for (const key of toTestOptions) {
49 | consumerConfig[key] = !defaultOptions[key];
50 | originalConfig[key] = defaultOptions[key];
51 | }
52 | // confirm they are not the same
53 | expect(originalConfig).not.toEqual(consumerConfig);
54 |
55 | // do config step
56 | const options = await init(consumerConfig);
57 |
58 | // confirm config is set by consumer
59 | expect(options).toHaveProperty(
60 | toTestOptions[0],
61 | consumerConfig[toTestOptions[0]],
62 | );
63 | expect(options).toHaveProperty(
64 | toTestOptions[1],
65 | consumerConfig[toTestOptions[1]],
66 | );
67 | expect(options).toHaveProperty(
68 | toTestOptions[2],
69 | consumerConfig[toTestOptions[2]],
70 | );
71 | });
72 | });
73 | });
74 |
--------------------------------------------------------------------------------
/test/utils/run-test.js:
--------------------------------------------------------------------------------
1 | import { lint } from "markdownlint/async";
2 |
3 | export async function runTest(strings, rule, ruleConfig) {
4 | const thisRuleName = rule.names[1];
5 |
6 | const config = {
7 | config: {
8 | default: false,
9 | [thisRuleName]: ruleConfig || true,
10 | },
11 | customRules: [rule],
12 | };
13 |
14 | const results = await Promise.all(
15 | strings.map((variation) => {
16 | const thisTestConfig = {
17 | ...config,
18 | strings: [variation],
19 | };
20 |
21 | return new Promise((resolve, reject) => {
22 | lint(thisTestConfig, (err, result) => {
23 | if (err) reject(err);
24 | resolve(result[0]);
25 | });
26 | });
27 | }),
28 | );
29 |
30 | return results.flat();
31 | }
32 |
--------------------------------------------------------------------------------