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

[eslint] Enforce @ignore before comment #3611

Merged
merged 1 commit into from
Mar 13, 2016
Merged

[eslint] Enforce @ignore before comment #3611

merged 1 commit into from
Mar 13, 2016

Conversation

mbrookes
Copy link
Member

@mbrookes mbrookes commented Mar 6, 2016

  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

Adds a custom eslint rule to enforce placing @ignore at the start of the comment block.

Resolves: #3589 (comment)

@alitaheri
Copy link
Member

WOW O.O That was fast 👍 👍 👍 Thanks 😍

@callemall/material-ui Take a look and merge, somebody else 😆

@@ -58,6 +58,7 @@ rules:
prefer-const: 2
prefer-template: 2
quotes: [2, single, avoid-escape]
require-@ignore-before-comment: 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we enforce it with 2?

@oliviertassinari
Copy link
Member

My sublime text plugin is having trouble finding the definition of this rule. Is this only me?

@alitaheri
Copy link
Member

@oliviertassinari It's a custom rule, I don't think IDEs support them. Besides the build is passing, so I'm pretty sure it's IDE related.

@nathanmarks
Copy link
Member

@alitaheri @oliviertassinari

I see the same thing. This is making the top line of every file show a warning in my IDE 👎

src/DropDownMenu/DropDownMenu.jsx: line 1, col 1, Warning - Definition for rule 'require-@ignore-before-comment' was not found (require-@ignore-before-comment)

@nathanmarks
Copy link
Member

This does not work with eslint either. It is not an IDE issue:

PoweredbySearch on Powereds-MacBook-Pro-2.local in ~/Development/repos/nathanmarks/material-ui(23h32m|pr/3611)
$ node_modules/.bin/eslint src

/Users/PoweredbySearch/Development/repos/nathanmarks/material-ui/src/card/index.js
  1:1  warning  Definition for rule 'require-@ignore-before-comment' was not found  require-@ignore-before-comment

/Users/PoweredbySearch/Development/repos/nathanmarks/material-ui/src/date-picker/index.js
  1:1  warning  Definition for rule 'require-@ignore-before-comment' was not found  require-@ignore-before-comment

/Users/PoweredbySearch/Development/repos/nathanmarks/material-ui/src/DropDownMenu/index.js
  1:1  warning  Definition for rule 'require-@ignore-before-comment' was not found  require-@ignore-before-comment

/Users/PoweredbySearch/Development/repos/nathanmarks/material-ui/src/grid-list/index.js
  1:1  warning  Definition for rule 'require-@ignore-before-comment' was not found  require-@ignore-before-comment

/Users/PoweredbySearch/Development/repos/nathanmarks/material-ui/src/hoc/selectable-enhance.js
  1:1  warning  Definition for rule 'require-@ignore-before-comment' was not found  require-@ignore-before-comment

/Users/PoweredbySearch/Development/repos/nathanmarks/material-ui/src/index.js
  1:1  warning  Definition for rule 'require-@ignore-before-comment' was not found  require-@ignore-before-comment

# it keeps going ;)

... etc

@nathanmarks nathanmarks added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI PR: Needs Review and removed PR: Review Accepted labels Mar 7, 2016
@nathanmarks
Copy link
Member

@mbrookes @alitaheri

It looks like the current implementation is tied to the gulp config. Can this be setup so that we can run eslint without gulp and have the rule run?

Ideally we'd be able to just run node_modules/.bin/eslint src (without args). Does this mean having the rule setup as some sort of plugin for eslint instead of a script in the repo?

@alitaheri
Copy link
Member

@mbrookes rebase please 😅

@alitaheri alitaheri added PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: Needs Review PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Mar 8, 2016
@mbrookes mbrookes added the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Mar 8, 2016
@nathanmarks
Copy link
Member

@alitaheri this cannot be merged as is, it was gulp-only the way it was configured. That's why I added "Need Revision".

I think it should be implemented as a plugin.

We could use --rulesdir, but I think it would be nicer to have it as a plugin outside of the repo. eslint looks like it has an easy plugin system to drop this into: http://eslint.org/docs/developer-guide/working-with-plugins @mbrookes

@nathanmarks nathanmarks self-assigned this Mar 8, 2016
@alitaheri
Copy link
Member

but I think it would be nicer to have it as a plugin outside of the repo,

Yeah I agree 👍 👍 @mbrookes Maybe you can extend it a bit and make it a general purpose rule of it own. I'm sure many can benefit from it 👍

@mbrookes mbrookes added PR: Needs Review and removed PR: out-of-date The pull request has merge conflicts and can't be merged PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Mar 9, 2016
@mbrookes
Copy link
Member Author

mbrookes commented Mar 9, 2016

Oddly eslint doesn't support rulesDir in .eslintrc - the one place you'd really want it (which is why I went the gulp route to try to avoid an external dependancy).

As we've dropped gulp, and to make this work effectively across editors, it requires a custom plugin: https://github.com/mbrookes/eslint-plugin-material-ui

We can add additional rules to that as needed.

@mbrookes mbrookes added the Core label Mar 9, 2016
@oliviertassinari
Copy link
Member

What about publishing the eslint rules package for Material-UI from this repository?

@mbrookes
Copy link
Member Author

That would be better. Shall I hang it off root?

@oliviertassinari
Copy link
Member

Where should we put the folder for this new npm package? That's the hardest part.

We could follow https://github.com/facebook/react/tree/master/packages with /packages/eslint-plugin-material-ui/ and as suggested by #3670, having a script that move what is needed under /packages/material-ui/, and later /packages/material-ui-native/.

What do you think?

@mbrookes
Copy link
Member Author

Well I wouldn't advocate rearranging the directory structure just to accommodate this small package, especially as it is only a dev dependancy, rather than a package to be published.

I had put it in / before I read your suggestion, and it's working fine, although I may have uncovered a Travis bug with locally installed npm packages. (I changed package.json to install eslint-plugin-material-ui from the local directory rather than npm, which works here, but not, apparently, on Travis.)

@nathanmarks
Copy link
Member

@mbrookes there's some great discussions going on in issue #3670 RE folder structure

@mbrookes
Copy link
Member Author

@nathanmarks - yes, it was based on a discussion @alitaheri and I had earlier. But as I said above, this is only a dev dependancy, rather than a package to be published (assuming we can get past the Travis issue without resorting to publishing to npm), but even if not, it's still not a for-public-consumption package, so belongs within material-ui rather than along side it.

That is to say, even if material-ui goes into packages (an unnecessary layer of nesting IMHO, but I'll save that for the other discussion), this package would still reside within it.

@mbrookes
Copy link
Member Author

Thanks @oliviertassinari, it looks like the problem was the blanket exclusion of lib in .gitignore whic h meant the important part of the package wasn't included in the commit!

This .gitignore rule would also have caused us problems with @newoga's solution to the directory reorg name-clash issue: #2679 (comment)

I've made it /lib instead, and now all is good.

@@ -0,0 +1,50 @@
/**
* @fileoverview Prevent the usage of sessionStorage and localStorage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbrookes Think this comment section needs a cleanup 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, whoops! 😲

@nathanmarks nathanmarks added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Mar 13, 2016
@nathanmarks
Copy link
Member

@oliviertassinari @mbrookes are we happy with this sitting in the root for now? Or should it go under a subfolder?

@oliviertassinari
Copy link
Member

That's fine for me under the root folder for now.

"scripts": {
"test": "node_modules/mocha/bin/_mocha -- tests/lib/**/*.js"
},
"devDependencies": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these since the root repo has both mocha and eslint?

@nathanmarks
Copy link
Member

@oliviertassinari FYI, the /packages thing is very widespread! eslint do it for their own rule plugin too: https://github.com/eslint/eslint/tree/master/packages/eslint-config-eslint

@mbrookes
Copy link
Member Author

I can move it to packages to get the ball rolling if that's the direction we're taking, or we can merge as is and move it later. Let me know.

@mbrookes mbrookes added PR: Needs Review and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Mar 13, 2016
@nathanmarks
Copy link
Member

@mbrookes did you just rebase? what about also adding [Core] to the last 2 commit messages?

@mbrookes
Copy link
Member Author

I'm assuming the commit's will get squashed, and I'll update the commit message then - not too fussed about the ones that will be deleted.

Since all of @oliviertassinari's eslint updates have [eslint] as the prefix, so I went with the for the PR title.

@nathanmarks
Copy link
Member

@mbrookes Ahhh sorry, I thought you just rebased/squashed because everything was outdated!

@mbrookes
Copy link
Member Author

No, you're right, I rebased, then noticed that the Stepper @ignores were already fixed, so dropped that commit and force pushed.

But haven't squashed yet... will do that if all looks good.

"name": "eslint-plugin-material-ui",
"version": "1.0.0",
"description": "Custom eslint rules for Material-UI",
"repository": "https://github.com/callemall/material-ui/packages/eslint-pluigin-material-ui",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in pluigin

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I knew I should have cut & pasted that! And I need 👓 .

@nathanmarks nathanmarks added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Mar 13, 2016
@mbrookes mbrookes added PR: Needs Review and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Mar 13, 2016
Add a custom eslint plugin with a rule to enforce that the docgen
@ignore tage be at the start of the comment.
@oliviertassinari
Copy link
Member

That looks good to me 👍.

@mbrookes
Copy link
Member Author

Thanks, that's good enough for me. 😄

mbrookes added a commit that referenced this pull request Mar 13, 2016
@mbrookes mbrookes merged commit bff5f4e into mui:master Mar 13, 2016
@mbrookes mbrookes deleted the docs-@ignore-before-comment branch March 19, 2016 01:24
@zannager zannager added the package: eslint Specific to eslint-plugin-material-ui label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: eslint Specific to eslint-plugin-material-ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants