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

check-examples and whitespace-based rules (like indent) #211

Closed
brettz9 opened this issue May 8, 2019 · 10 comments
Closed

check-examples and whitespace-based rules (like indent) #211

brettz9 opened this issue May 8, 2019 · 10 comments

Comments

@brettz9
Copy link
Collaborator

brettz9 commented May 8, 2019

As currently implemented, check-examples has issues when the rule is indent as initial spacing is stripped out during parsing. May need to tweak parsing or use jsdocNode.

@slieker-d
Copy link

Can confirm. Having the same issue.

@brettz9
Copy link
Collaborator Author

brettz9 commented May 24, 2019

Be aware that in the meantime you can use overrides to disable the indent or other rules only for examples--using the rule in conjunction with settings.jsdoc.matchingFileName, e.g., {settings: {jsdoc: {matchingFileName: "dummy.md"}}} (in this case, to get the same rules one has for Markdown files--and possible use with eslint-plugin-markdown, but you could match against any file or file type) and then setting your .eslintrc.*'s overrrides to match the file or extension you have set up jsdoc to match against, e.g.,

overrides: [
  {
    files: ["**/*.md"],
    rules: {
      indent: 'off'
    }
  }
]

You can then have your other rules continue to apply to your non-example (or non-Markdown) code without disabling non-indent rules for your examples.

@slieker-d
Copy link

I added the overrides section to our .eslintrc.json file, but we're still getting this:

image

@slieker-d
Copy link

This is our entire eslintrc file:

{
    "env": {
        "es6": true,
        "node": true
    },
    "extends": ["airbnb-base", "plugin:jest/recommended"],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly",
        "jest": "readonly"
    },
    "parserOptions": {
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": [
        "jest",
        "jsdoc"
    ],
    "rules": {
        "jest/no-disabled-tests": "warn",
        "jest/no-focused-tests": "error",
        "jest/no-identical-title": "error",
        "jest/prefer-to-have-length": "warn",
        "jest/valid-expect": "error",

        "jsdoc/check-alignment": 1,
        "jsdoc/check-examples": 1,
        "jsdoc/check-indentation": 0,
        "jsdoc/check-param-names": 1,
        "jsdoc/check-syntax": 1,
        "jsdoc/check-tag-names": 1,
        "jsdoc/check-types": 1,
        "jsdoc/implements-on-classes": 1,
        "jsdoc/match-description": 1,
        "jsdoc/newline-after-description": 1,
        "jsdoc/no-types": 0,
        "jsdoc/no-undefined-types": 1,
        "jsdoc/require-description": 1,
        "jsdoc/require-description-complete-sentence": 1,
        "jsdoc/require-example": 1,
        "jsdoc/require-hyphen-before-param-description": 0,
        "jsdoc/require-jsdoc": 1,
        "jsdoc/require-param": 1,
        "jsdoc/require-param-description": 1,
        "jsdoc/require-param-name": 1,
        "jsdoc/require-param-type": 1,
        "jsdoc/require-returns": 1,
        "jsdoc/require-returns-check": 1,
        "jsdoc/require-returns-description": 1,
        "jsdoc/require-returns-type": 1,
        "jsdoc/valid-types": 1
    },
    "overrides": [{
        "files": ["**/*.js"],
        "rules": {
            "indent": "off"
        }
    }]
}

@brettz9
Copy link
Collaborator Author

brettz9 commented May 24, 2019

You also need in your case: {settings: {jsdoc: {matchingFileName: "dummy.js"}}}

But I'd suggest doing this instead:

  1. Add {settings: {jsdoc: {matchingFileName: "dummy.md"}}}
  2. Change your overrides to "files": ["**/*.md"],

This has three benefits:

  1. You can continue using indent with your other code JavaScript.
  2. You can continue using non-indent rules for your examples.
  3. If you choose "md" as the dummy extension, there is the added benefit that linting the JavaScript in your Markdown files (like README.md) tends to need similar rules disabled, such as eol-last, so you can use eslint-plugin-markdown to lint your Markdown JS with the same rules as in your examples if you wish. But that is optional--you could have separate rules for Markdown JS and separate for your @example's. If linting Markdown JavaScript, you also need to add --ext js,md to your eslint call, e.g., eslint --report-unused-disable-directives --ext js,md .).

@slieker-d
Copy link

This worked! Thank you very much!

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jul 13, 2019
…whitespace-related rules such as `indent` (fixes gajus#211)

feat(check-examples): add `paddedIndent` option
refactor: use `String.prototype.repeat` over lodash
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jul 13, 2019
…whitespace-related rules such as `indent` (fixes gajus#211)

feat(check-examples): add `paddedIndent` option
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jul 13, 2019
…whitespace-related rules such as `indent` (fixes gajus#211)
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Jul 13, 2019
…whitespace-related rules such as `indent` (fixes gajus#211)
@gajus
Copy link
Owner

gajus commented Jul 13, 2019

🎉 This issue has been resolved in version 15.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Jul 13, 2019
brettz9 added a commit to interfaced/eslint-plugin-jsdoc that referenced this issue Jul 14, 2019
* master: (46 commits)
  feat(require-description-complete-sentence): limit checking to certain default tags likely to have descriptions or by `tags` array for additional choices; fixes gajus#337
  docs(newline-after-description): indicate applies on doc block
  docs(match-description): add alias `desc` to separate column
  docs(match-description): indicate application by default to `description`/`desc` and allowance for `property`/`prop`; clarify
  fix(match-description): ensure `prop` and `property` matching excludes name
  testing(require-param): fix test source (part of gajus#332)
  testing(require-param): fix test expectation (part of gajus#332)
  docs: generate docs
  chore: update devDeps (eslint-config-canonical, gitdown)
  fix(no-undefined-types): ensure working in all contexts; fixes gajus#324
  refactor(iterateJsdoc): reduce retrieval calls
  docs(check-examples): allow for whitespace at end
  feat(check-examples): add `paddedIndent` option
  fix(check-examples): preserve whitespace so as to report issues with whitespace-related rules such as `indent` (fixes gajus#211)
  chore(travis): fix Travis to use older unicorn version that supports Node 6 (and the canonical config that requires the earlier unicorn version)
  docs(require-returns, require-returns-check): indicate that these will report if multiple `returns` tags are present
  refactor: use `String.prototype.repeat` over lodash `repeat`
  refactor: apply (jsdoc-related) eslint rule fixes
  chore: add `lint-fix` script
  fix(newline-after-description): avoid matching duplicate or partial matches within tag descriptions after the block description; fixes gajus#328
  ...
@gajus
Copy link
Owner

gajus commented Sep 1, 2019

🎉 This issue has been resolved in version 15.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@brettz9
Copy link
Collaborator Author

brettz9 commented Oct 1, 2019

Reopening as the original issue was not actually resolved.

@brettz9
Copy link
Collaborator Author

brettz9 commented May 11, 2021

This should have been fixed earlier in v18.1.6. Closing but feel free to refile with any reproducible examples. v15.4.0 also made it easier to work with indents via the paddedIndent option in case one deliberately adds (a fixed amount of) padding whitespace before example code.

As an aside re: the .md extension, support has been added in ESLint for the likes of **/*.md/*.js to indicate JavaScript fenced blocks within Markdown. That may be a better current option. (See the check-examples docs.)

@brettz9 brettz9 closed this as completed May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants