Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Lint JavaScript in Markdown files? #3924

Open
pdehaan opened this issue Oct 30, 2018 · 0 comments
Open

Lint JavaScript in Markdown files? #3924

pdehaan opened this issue Oct 30, 2018 · 0 comments

Comments

@pdehaan
Copy link
Contributor

pdehaan commented Oct 30, 2018

Not super important, but I saw this in my tweets and thought it was pretty interesting: https://github.com/eslint/eslint-plugin-markdown

I quickly ran it on the repo and didn't see anything problematic, but not sure if it's worth its adding or not.

diff --git a/.eslintrc b/.eslintrc
index 6ae90837..16a53b44 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -5,6 +5,19 @@ extends:
   - plugin:react/recommended
   - plugin:mozilla/recommended

+overrides:
+  -
+    files: ["**/*.md"]
+    parserOptions:
+      ecmaFeatures:
+        impliedStrict: true
+    plugins:
+      - markdown
+    rules:
+      import/no-unresolved: off
+      no-console: off
+      strict: off
+
 plugins:
   - import
   - flowtype
(END)
iff --git a/package.json b/package.json
index e950365f..38fabddb 100644
--- a/package.json
+++ b/package.json
@@ -73,6 +75,7 @@
     "eslint": "4.15.0",
     "eslint-plugin-flowtype": "3.0.0",
     "eslint-plugin-import": "2.14.0",
+    "eslint-plugin-markdown": "1.0.0-rc.0",
     "eslint-plugin-mozilla": "0.16.1",
     "eslint-plugin-no-unsanitized": "3.0.2",
     "eslint-plugin-react": "7.11.1",
@@ -145,6 +150,7 @@
     "lint": "npm-run-all lint:*",
     "lint:styles": "sass-lint --verbose 'frontend/src/styles/**/*.scss' 'frontend/src/app/**/*.scss'",
     "lint:js": "eslint ./gulpfile.babel.js ./webpack.config.js './frontend/{src,tests}/**/*.{js,jsx}'",
+    "lint:md": "eslint '**/*.md' --ext=.md",
     "test": "cd frontend && mocha --require @babel/register --require test-setup.js --recursive \"test\" \"src/**/tests.js\"",
     "flow": "flow frontend",
     "l10n:extract": "node bin/extract-strings.js",
(END)

But there would be lots of tweaking since not all snippets are standalone and expect React or other things to be imported, so it may be lots of juggling of rules to make sure we ignore certain rules/configs.


I think this was my result from the first time I got it to run successfully:

$ npm run lint:md

> testpilot@1.0.0 lint:md /Users/pdehaan/dev/github/mozilla/testpilot
> eslint '**/*.md' --ext=.md

/Users/pdehaan/dev/github/mozilla/testpilot/docs/development/storybook.md
  166:8   error  Strings must use doublequote                     quotes
  168:44  error  'Component' is not defined                       no-undef
  173:9   error  'React' must be in scope when using JSX          react/react-in-jsx-scope
  182:7   error  'React' must be in scope when using JSX          react/react-in-jsx-scope
  209:31  error  'Component' is not defined                       no-undef
  211:12  error  'React' must be in scope when using JSX          react/react-in-jsx-scope
  211:22  error  Missing semicolon                                semi
  215:16  error  'connect' is not defined                         no-undef
  215:34  error  'mapStateToProps' is not defined                 no-undef
  215:51  error  'mapDispatchToProps' is not defined              no-undef

/Users/pdehaan/dev/github/mozilla/testpilot/docs/metrics/readme.md
   75:25  error    Strings must use doublequote                     quotes
   77:7   error    'analytics' is assigned a value but never used   no-unused-vars
   78:8   error    Strings must use doublequote                     quotes
   79:7   error    Strings must use doublequote                     quotes
   80:7   error    Strings must use doublequote                     quotes
   81:9   error    Strings must use doublequote                     quotes
   82:7   error    Strings must use doublequote                     quotes
   83:8   error    Strings must use doublequote                     quotes
   91:1   error    'analytics' is not defined                       no-undef
   92:14  error    Strings must use doublequote                     quotes
   92:26  error    Strings must use doublequote                     quotes
   93:10  error    Strings must use doublequote                     quotes
   94:10  error    Strings must use doublequote                     quotes
   97:17  error    Strings must use doublequote                     quotes
   97:53  error    Missing semicolon                                semi
  100:19  error    Strings must use doublequote                     quotes
  100:53  error    Missing semicolon                                semi

✖ 31 problems (29 errors, 2 warnings)
  17 errors, 0 warnings potentially fixable with the `--fix` option.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant