-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
feat: Docusaurus ESLint plugin to enforce best Docusaurus practices #7206
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
52f00e4
feat: add eslint plugin
elias-pap e6ac161
refactor
Josh-Cena e48d6e1
add tests
Josh-Cena 5375beb
fixups!
Josh-Cena e33bcd2
fix(no-dynamic-i18n-messages): make translate() recognize template li…
elias-pap 19a7f89
refactor: rename rule no-dynamic-i18n-messages --> string-literal-i18…
elias-pap 7ae0e64
feat: add ignoreStrings option and refactor
elias-pap aa58521
docs: migrate docs to /docs/api/plugins
elias-pap 8776087
docs: fix anchor links in README.md
elias-pap 3d5ecd0
fix: add some ignored strings
elias-pap 9f04ae1
docs: update eslint-plugin docs
elias-pap 05e2fed
fix: update README link
elias-pap 492615f
docs: various updates
elias-pap 3fd35d6
Merge branch 'main' into add-eslint-plugin
Josh-Cena 05a5f3c
Merge branch 'main' into add-eslint-plugin
Josh-Cena 35ef3b2
address reviews
Josh-Cena beabcf4
wording polish
Josh-Cena ecdc3bd
add npmignore
Josh-Cena d1d9add
fix all internal warnings
Josh-Cena 50f0de4
doc improvements
Josh-Cena 40cfd23
fix test
Josh-Cena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10000
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
module.exports = { | ||
extends: ['../../.eslintrc.js', 'plugin:eslint-plugin/recommended'], | ||
}; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
copyUntypedFiles.mjs | ||
.tsbuildinfo | ||
tsconfig* | ||
__tests__ | ||
|
||
.eslintrc.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# `@docusaurus/eslint-plugin` | ||
|
||
ESLint plugin to enforce best Docusaurus practices. | ||
|
||
## Usage | ||
|
||
See [eslint-plugin documentation](https://docusaurus.io/docs/api/misc/@docusaurus/eslint-plugin). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const requireIndex = require('requireindex'); | ||
|
||
module.exports = { | ||
rules: requireIndex(`${__dirname}/rules`), | ||
configs: { | ||
recommended: { | ||
rules: { | ||
'@docusaurus/string-literal-i18n-messages': 'error', | ||
}, | ||
}, | ||
all: { | ||
rules: { | ||
'@docusaurus/string-literal-i18n-messages': 'error', | ||
'@docusaurus/no-untranslated-text': 'warn', | ||
}, | ||
}, | ||
}, | ||
}; |
147 changes: 147 additions & 0 deletions
147
packages/eslint-plugin/lib/rules/__tests__/no-untranslated-text.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const rule = require('../no-untranslated-text'); | ||
const {RuleTester} = require('eslint'); | ||
const {getCommonValidTests} = require('../../util'); | ||
|
||
const errorsJSX = [{messageId: 'translateChildren', type: 'JSXElement'}]; | ||
const errorsJSXFragment = [ | ||
{messageId: 'translateChildren', type: 'JSXFragment'}, | ||
]; | ||
|
||
const ruleTester = new RuleTester({ | ||
parserOptions: { | ||
ecmaVersion: 2022, | ||
ecmaFeatures: {jsx: true}, | ||
}, | ||
}); | ||
ruleTester.run('no-untranslated-text', rule, { | ||
valid: [ | ||
...getCommonValidTests(), | ||
{ | ||
code: '<Component>·</Component>', | ||
options: [{ignoreStrings: ['·', '—', '×']}], | ||
}, | ||
{ | ||
code: '<Component>· </Component>', | ||
options: [{ignoreStrings: ['·', '—', '×']}], | ||
}, | ||
{ | ||
code: '<Component> · </Component>', | ||
options: [{ignoreStrings: ['·', '—', '×']}], | ||
}, | ||
{ | ||
code: '<Component>· ·</Component>', | ||
options: [{ignoreStrings: ['·', '—', '×']}], | ||
}, | ||
{ | ||
code: '<Component>· — ×</Component>', | ||
options: [{ignoreStrings: ['·', '—', '×']}], | ||
}, | ||
{ | ||
code: '<Component>{"·"}</Component>', | ||
options: [{ignoreStrings: ['·']}], | ||
}, | ||
{ | ||
code: "<Component>{'·'}</Component>", | ||
options: [{ignoreStrings: ['·']}], | ||
}, | ||
{ | ||
code: '<Component>{`·`}</Component>', | ||
options: [{ignoreStrings: ['·', '—', '×']}], | ||
}, | ||
{ | ||
code: '<Component>Docusaurus</Component>', | ||
options: [{ignoreStrings: ['Docusaurus']}], | ||
}, | ||
{ | ||
code: '<Component>​</Component>', | ||
options: [{ignoreStrings: ['']}], | ||
}, | ||
{ | ||
code: `<> | ||
{' · '} | ||
</>`, | ||
options: [{ignoreStrings: ['·', "'"]}], | ||
}, | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: '<Component>text</Component>', | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
code: '<Component> text </Component>', | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
code: '<Component>"text"</Component>', | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
code: "<Component>'text'</Component>", | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
code: '<Component>`text`</Component>', | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
code: '<Component>{"text"}</Component>', | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
code: "<Component>{'text'}</Component>", | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
code: '<Component>{`text`}</Component>', | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
code: '<>text</>', | ||
errors: errorsJSXFragment, | ||
}, | ||
{ | ||
code: '<Component>· — ×</Component>', | ||
errors: errorsJSX, | ||
options: [{ignoreStrings: ['·', '—']}], | ||
}, | ||
{ | ||
code: '<Component>··</Component>', | ||
errors: errorsJSX, | ||
options: [{ignoreStrings: ['·', '—', '×']}], | ||
}, | ||
{ | ||
code: '<Component> ·· </Component>', | ||
errors: errorsJSX, | ||
options: [{ignoreStrings: ['·', '—', '×']}], | ||
}, | ||
{ | ||
code: '<Component>"·"</Component>', | ||
errors: errorsJSX, | ||
options: [{ignoreStrings: ['·', '—', '×']}], | ||
}, | ||
{ | ||
code: "<Component>'·'</Component>", | ||
errors: errorsJSX, | ||
options: [{ignoreStrings: ['·', '—', '×']}], | ||
}, | ||
{ | ||
code: '<Component>`·`</Component>', | ||
errors: errorsJSX, | ||
options: [{ignoreStrings: ['·', '—', '×']}], | ||
}, | ||
{ | ||
code: '<Component>Docusaurus</Component>', | ||
errors: errorsJSX, | ||
options: [{ignoreStrings: ['Docu', 'saurus']}], | ||
}, | ||
], | ||
}); |
51 changes: 51 additions & 0 deletions
51
packages/eslint-plugin/lib/rules/__tests__/string-literal-i18n-messages.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const rule = require('../string-literal-i18n-messages'); | ||
const {RuleTester} = require('eslint'); | ||
const {getCommonValidTests} = require('../../util'); | ||
|
||
const errorsJSX = [{messageId: 'translateChildren', type: 'JSXElement'}]; | ||
const errorsFunc = [{messageId: 'translateArg', type: 'Identifier'}]; | ||
|
||
const ruleTester = new RuleTester({ | ||
parserOptions: { | ||
ecmaVersion: 2022, | ||
ecmaFeatures: {jsx: true}, | ||
}, | ||
}); | ||
ruleTester.run('string-literal-i18n-messages', rule, { | ||
valid: [...getCommonValidTests()], | ||
|
||
invalid: [ | ||
{ | ||
code: '<Translate>{text}</Translate>', | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
code: '<Translate>Hi {text} my friend</Translate>', | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
code: '<Translate> {text} </Translate>', | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
code: '<Translate>`{text}`</Translate>', | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
// eslint-disable-next-line no-template-curly-in-string | ||
code: '<Translate>{`${text}`}</Translate>', | ||
errors: errorsJSX, | ||
}, | ||
{ | ||
code: 'translate({message: metaTitle})', | ||
errors: errorsFunc, | ||
}, | ||
], | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.