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

[WIP] Linters - eslint, jscs, jshint & scss #221

Closed
wants to merge 7 commits into from
Closed

[WIP] Linters - eslint, jscs, jshint & scss #221

wants to merge 7 commits into from

Conversation

himdel
Copy link

@himdel himdel commented Jul 22, 2016

This adds two more linters to miq-bot - eslint (for javascript) and scss-lint (for sass/scss).

Their JSON output has a different structure, so this also adds a convert_parsed method to Linter::Base, and overrides to convert to the rubocop format:

eslint output:

[
  {
    filePath: "foo/bar",
    messages: [
      {
        ruleId: "baz",
        severity: 1,
        message: "quux",
        line: 4,
        column: 5,
      },
    ],
  },
]

scss output:

{
  "foo/bar": [
    {
      line: 4,
      column: 5,
      severity: "warning",
      reason: "quux",
      linter: "baz",
    },
  ],
}

converted output:

{
  files: [
    {
      path: "foo/bar",
      offenses: [
        {
          severity: "warning",
          message: "quux",
          location: {
            line: 4,
            column: 5,
          },
          cop_name: "baz",
        },
      ],
    },
  ],
  summary: {
    target_file_count: 1,
    offense_count: 1,
  },
}

TODO:

@romanblanco
Copy link
Member

related to issue ManageIQ/manageiq#2389

@Fryguy
Copy link
Member

Fryguy commented Sep 6, 2016

You may also need to deal with this...perhaps not this PR, but...

header1 = "Checked #{"commit".pluralize(commits.length)} #{commit_range_text} with ruby #{RUBY_VERSION}, rubocop #{rubocop_version}, and haml-lint #{hamllint_version}"

@Fryguy
Copy link
Member

Fryguy commented Oct 18, 2016

@himdel Is this good to go? Or is there more stuff to be done?

@himdel
Copy link
Author

himdel commented Oct 19, 2016

@Fryguy this it's really missing only 2 things now..

a) verify that all the linter's JSON output formats are compatible enough

b) cache node_modules - in the end I think the fastest solution is to shasum package.json and .. essentially set NODE_PATH=whatever$(sha1sum packages.json) so that we have to run npm install only when the dir is missing

@miq-bot
Copy link
Member

miq-bot commented Jan 5, 2017

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@chessbyte
Copy link
Member

@himdel please rebase and push again

…parsed

..so that these can be overriden in linters that have special parsing/running needs

the default `parse_output` is the original JSON.parse + exceptions and could be overriden for linters that don't output JSON

the default `convert_parsed` is an identity function, but is needed by eslint & scss to convert between the different JSON formats
converting from each format to the one used by rubocop

eslint output:

```
[
  {
    filePath: "foo/bar",
    messages: [
      {
        ruleId: "baz",
        severity: 1,
        message: "quux",
        line: 4,
        column: 5,
      },
    ],
  },
]
```

scss output:

```
{
  "foo/bar": [
    {
      line: 4,
      column: 5,
      severity: "warning",
      reason: "quux",
      linter: "baz",
    },
  ],
}
```

converted output:

```
{
  files: [
    {
      path: "foo/bar",
      offenses: [
        {
          severity: "warning",
          message: "quux",
          location: {
            line: 4,
            column: 5,
          },
          cop_name: "baz",
        },
      ],
    },
  ],
  summary: {
    target_file_count: 1,
    offense_count: 1,
  },
}
```
@miq-bot
Copy link
Member

miq-bot commented Jan 11, 2017

Checked commits https://github.com/himdel/miq_bot/compare/c1966dde3a5e20dcccb836c123a7ff05ddb95a4b~...156d75696f87554809da6d49aad24493230a7712 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
5 files checked, 5 offenses detected

Gemfile

lib/linter/base.rb

lib/linter/eslint.rb

lib/linter/scss.rb

  • 💣 💥 🔥 🚒 - Line 43, Col 1 - Syntax - unexpected token kEND
    (Using Ruby 2.0 parser; configure using TargetRubyVersion parameter, under AllCops)

end
end

# overriden in linters with different JSON format
Copy link
Member

Choose a reason for hiding this comment

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

comment typo overriden -> overridden

files = array.map { |f| convert_file(f) }

{:files => files,
:summary => {:offense_count => files.reduce(0) { |memo, f| memo + f.offenses.count },
Copy link
Member

Choose a reason for hiding this comment

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

I believe files.reduce(0) { |memo, f| memo + f.offenses.count } can be simplified to files.map { |f| f.offenses.count }.reduce(:+)

@miq-bot
Copy link
Member

miq-bot commented Jan 16, 2017

This pull request is not mergeable. Please rebase and repush.

@Fryguy
Copy link
Member

Fryguy commented Feb 23, 2018

#406 will likely supercede this

@himdel
Copy link
Author

himdel commented Jun 16, 2020

Or #500 will :)

@Fryguy
Copy link
Member

Fryguy commented Jun 25, 2020

going to close this in favor of Pronto work as it's being revived.

@Fryguy Fryguy closed this Jun 25, 2020
@himdel
Copy link
Author

himdel commented Oct 14, 2020

@NickLaMuro for eslint, we need the following npm packages:

  • babel-eslint
  • eslint
  • eslint-config-airbnb
  • eslint-config-angular
  • eslint-plugin-angular
  • eslint-plugin-import
  • eslint-plugin-jest
  • eslint-plugin-jsx-a11y
  • eslint-plugin-react

You can assume current versions, I'll be updating them on ui-classic side soon. (=> ManageIQ/manageiq-ui-classic#7423)
(ui-classic also has eslint-{config,plugin}-standard and eslint-config-promise but these are unused)

I guess it makes sense to just copy those dependencies to manageiq-style, and update both places.


One more catch .. the .eslintrc.json configfile can be in any directory, we need them all (including the relative symlinks, but they can be copies).
(It inherits from parent dirs, so we can have spec-only globals, etc.)

@NickLaMuro
Copy link
Member

NickLaMuro commented Oct 14, 2020

Turns out it is probably for the best that we aren't using proto for this as it looks like the pronto-eslint gem under the hood uses eslintrb, which is super ancient, and uses a version of eslint that is very much out of date:

https://github.com/zendesk/eslintrb/tree/master/vendor [ref]

And probably doesn't have all of the plugins you want.


That said, the list of plugins is going to be a bit of a nightmare to source consistently, so we might want to consider vendoring them into this repo to avoid inconsistencies. This would mean that when run via a potential future "cli client", there is no concern about potentially getting the wrong dependencies.

Alternatively, we could consider creating a stand-alone repo for doing just that, and it can also have a gem component for ruby projects that want to consume it, with the process of updating it just being done with whatever standard JS means is preferred.

@himdel
Copy link
Author

himdel commented Oct 14, 2020

Oh, well, a CLI client would be great for miq-bot development, but that may just be complicating matters now.
I still expect UI developers to run eslint locally, let's not complicate it. (Not to mention it's impossible for editors to run a custom miq-bot cli linter.)

What about something as simple as having a manageiq-style package.json with the dependencies (and possibly a .nvmrc with a node version), and a base .eslintrc.json to apply when no root eslintrc.json is present.

The primary goal is to get this running on the bot, and it can just be statically installed there.

@himdel
Copy link
Author

himdel commented Oct 14, 2020

The primary goal is to get this running on the bot, and it can just be statically installed there.

In fact, I'd propose this directory structure, if doable...

root/
  package.json (from manageiq-style)
  .eslintrc.json (from manageiq-style)
  node_modules/ (by running yarn in root/)
  $repo/

That way, yarn run eslint $repo should work, pick up $repo/.eslintrc.json if present, fallback to root/.eslintrc.json if not.
And root/ can be cached on the bot, only updated when manageiq-style changes, while root/$repo gets regularly updated.

@himdel
Copy link
Author

himdel commented Oct 14, 2020

(and since $repo can be a tempdir with a random name, it should still work in parallel)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants