Skip to content

Commit

Permalink
fix(check-examples): use jsdoc-defaults, jsdoc-params, and `jsd…
Browse files Browse the repository at this point in the history
…oc-properties` as default extensions to allow these to have their own overrides
  • Loading branch information
brettz9 committed Oct 19, 2020
1 parent 2de1011 commit 39fb1cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
9 changes: 6 additions & 3 deletions .README/rules/check-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ by decreasing precedence:
[other plugins](https://github.com/eslint/eslint-plugin-markdown), e.g.,
if one sets `matchingFileName` to `dummy.md` so that `@example` rules will
follow one's Markdown rules). For `@example` only.
* `matchingFileNameDefaults` - As with `matchingFileName` but for use with `checkDefaults`.
* `matchingFileNameParams` - As with `matchingFileName` but for use with `checkParams`.
* `matchingFileNameProperties` As with `matchingFileName` but for use with `checkProperties`.
* `matchingFileNameDefaults` - As with `matchingFileName` but for use with
`checkDefaults` and defaulting to `.jsdoc-defaults` as extension.
* `matchingFileNameParams` - As with `matchingFileName` but for use with
`checkParams` and defaulting to `.jsdoc-params` as extension.
* `matchingFileNameProperties` As with `matchingFileName` but for use with
`checkProperties` and defaulting to `.jsdoc-properties` as extension.
* `checkEslintrc` - Defaults to `true` in adding rules
based on an `.eslintrc.*` file. Setting to `false` corresponds to
ESLint's [`--no-eslintrc`](https://eslint.org/docs/user-guide/command-line-interface#--no-eslintrc).
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,12 @@ by decreasing precedence:
[other plugins](https://github.com/eslint/eslint-plugin-markdown), e.g.,
if one sets `matchingFileName` to `dummy.md` so that `@example` rules will
follow one's Markdown rules). For `@example` only.
* `matchingFileNameDefaults` - As with `matchingFileName` but for use with `checkDefaults`.
* `matchingFileNameParams` - As with `matchingFileName` but for use with `checkParams`.
* `matchingFileNameProperties` As with `matchingFileName` but for use with `checkProperties`.
* `matchingFileNameDefaults` - As with `matchingFileName` but for use with
`checkDefaults` and defaulting to `.jsdoc-defaults` as extension.
* `matchingFileNameParams` - As with `matchingFileName` but for use with
`checkParams` and defaulting to `.jsdoc-params` as extension.
* `matchingFileNameProperties` As with `matchingFileName` but for use with
`checkProperties` and defaulting to `.jsdoc-properties` as extension.
* `checkEslintrc` - Defaults to `true` in adding rules
based on an `.eslintrc.*` file. Setting to `false` corresponds to
ESLint's [`--no-eslintrc`](https://eslint.org/docs/user-guide/command-line-interface#--no-eslintrc).
Expand Down
12 changes: 6 additions & 6 deletions src/rules/checkExamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ export default iterateJsdoc(({
sources.forEach(checkRules);
};

const getFilenameInfo = (filename) => {
const getFilenameInfo = (filename, ext = 'md') => {
let defaultFileName;
if (!filename) {
const jsFileName = context.getFilename();
if (typeof jsFileName === 'string' && jsFileName.includes('.')) {
defaultFileName = jsFileName.replace(/\..*?$/, '.md');
defaultFileName = jsFileName.replace(/\..*?$/, `.${ext}`);
} else {
defaultFileName = 'dummy.md';
defaultFileName = `dummy.${ext}`;
}
}

Expand All @@ -234,7 +234,7 @@ export default iterateJsdoc(({
};

if (checkDefaults) {
const filenameInfo = getFilenameInfo(matchingFileNameDefaults);
const filenameInfo = getFilenameInfo(matchingFileNameDefaults, 'jsdoc-defaults');
utils.forEachPreferredTag('default', (tag, targetTagName) => {
checkSource({
source: tag.description,
Expand All @@ -244,7 +244,7 @@ export default iterateJsdoc(({
});
}
if (checkParams) {
const filenameInfo = getFilenameInfo(matchingFileNameParams);
const filenameInfo = getFilenameInfo(matchingFileNameParams, 'jsdoc-params');
utils.forEachPreferredTag('param', (tag, targetTagName) => {
if (typeof tag.default !== 'string') {
return;
Expand All @@ -257,7 +257,7 @@ export default iterateJsdoc(({
});
}
if (checkProperties) {
const filenameInfo = getFilenameInfo(matchingFileNameProperties);
const filenameInfo = getFilenameInfo(matchingFileNameProperties, 'jsdoc-properties');
utils.forEachPreferredTag('property', (tag, targetTagName) => {
if (typeof tag.default !== 'string') {
return;
Expand Down

0 comments on commit 39fb1cb

Please sign in to comment.