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

Fix linting issues and update some of the rules #36

Closed
wants to merge 19 commits into from
Closed

Fix linting issues and update some of the rules #36

wants to merge 19 commits into from

Conversation

molant
Copy link
Member

@molant molant commented Mar 12, 2017

  • Added the TypeScript plugin,
  • Updated some of the eslint rules to be more compatible with TypeScript
  • Refactored the code to require less import for types and thus avoiding triggering the no-unused-variables
  • Added more spaces to the functions to make @alrra happy

This one supersedes pull #18

@molant molant mentioned this pull request Mar 12, 2017
@molant molant requested a review from alrra March 12, 2017 21:53
.eslintrc.json Outdated
@@ -10,7 +10,8 @@
},
"parser": "typescript-eslint-parser",
"plugins": [
"import"
"import",
"typescript"
Copy link
Contributor

Choose a reason for hiding this comment

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

@molant You also need to add eslint-plugin-typescript to the package.json file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added, good catch 🐟

.eslintrc.json Outdated
"yoda": ["error", "never"]
"yoda": ["error", "never"],

"typescript/type-annotation-spacing": "error"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe also add: typescript/no-unused-vars?

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 don't see that rule in the supported ones. Where is it coming from?

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems it's not yet in any published npm version.

src/lib/sonar.ts Outdated
@@ -8,13 +8,12 @@
// ------------------------------------------------------------------------------

import { EventEmitter2 as EventEmitter } from 'eventemitter2';
import * as _ from 'lodash';
// import * as _ from 'lodash';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just remove it until we actually use it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Completely forgot about this one

src/bin/sonar.ts Outdated
@@ -15,7 +15,9 @@ const debug = (process.argv.includes('--debug'));

// must do this initialization *before* other requires in order to work
if (debug) {

Copy link
Contributor

@alrra alrra Mar 12, 2017

Choose a reason for hiding this comment

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

IMHO, for the cases where there is just one line, it's overkill.

Copy link
Member Author

Choose a reason for hiding this comment

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

But we need to enable it in the entrance point for other to work as the comment says. Are you referring to something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you referring to something else?

Sorry for the confusion. I was referring to the empty lines. When there is just a single line (i.e.: require('debug').enable('sonar:*,-sonar:code-path');), it's overkill to add empty lines around it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Part of the rule. Don't think we can configure it at that level.

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've removed that rule and increase the number of max empty lines to 2 so the code can breath a bit more for you.

@@ -46,45 +45,56 @@ const defaultOptions = {
};

const builder: CollectorBuilder = (server: Sonar, config): Collector => {

Copy link
Contributor

Choose a reason for hiding this comment

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

When there are groups, like here, it makes sense to have the empty line. ✨

src/lib/types.ts Outdated
* @fileoverview Interfaces and enums used in different files in Sonar that do not belong in an specific place.
* @author Anton Molleda (@molant)
*/
'use strict';
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use --alwaysStrict?

Copy link
Member Author

Choose a reason for hiding this comment

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

AFAIK this file shouldn't even be in the final compile. It is used only to check that the types are OK. I added the alwaysStrict to the compiler options and set to never the strict rule in eslint.

@molant molant changed the title Fixing linting issues and updating some of the rules Fix linting issues and update some of the rules Mar 13, 2017
@molant
Copy link
Member Author

molant commented Mar 13, 2017

@alrra you can take another look and merge if it is OK.

alrra and others added 14 commits March 13, 2017 12:49
Change made so that the process of opening the `LICENSE` file is
easier for non-technical people.
Also, changed folder structure and add dependencies.
From https://docs.npmjs.com/files/package.json#private:

 " If you set `"private": true` in your `package.json`, then `npm`
   will refuse to publish it. This is a way to prevent accidental
   publication of private repositories. "
* Remove reference to `.travis.yml` as that file is not included.
* Add link to the site instead of explaining every line, and add
  comments only for when the information cannot be found on the site.
* Add `trim_trailing_whitespace` property.
Most people will expect `.sonarrc` to work as in general `.<name>rc`
files seem to be the preferred way for people to store CLI specific
configurations.
For the time being we decided to keep things simple and only support
JSON, as supporting multiple formats can complicate things and even
create some problems.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Ref: eslint/eslint#4406 (comment)
* Added the TypeScript plugin to ESLint
* Tweaked the rules to be more compatible with our style and TS
* Refactored the code to require less `imports` so less `no-unused-vars` errors
* Fixed all other linting issues
@alrra alrra closed this in 2afd1a9 Mar 13, 2017
alrra pushed a commit that referenced this pull request Mar 13, 2017
* Add ESLint TypeScript plugin.
* Tweak rules to be more compatible with the current style
  and TypeScript.
* Refactor code to require less `imports`, thus, generate
  less `no-unused-vars` errors.
* Fix other linting issues.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Close #36
alrra pushed a commit that referenced this pull request Mar 13, 2017
* Add ESLint TypeScript plugin.
* Tweak rules to be more compatible with the current style
  and TypeScript.
* Refactor code to require less `imports`, thus, generate
  less `no-unused-vars` errors.
* Fix other linting issues.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Close #36
@molant molant deleted the typescript branch March 17, 2017 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants