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

Add Airbnb JavaScript Style Guide for eslint #28

Merged
merged 4 commits into from
Jan 8, 2018
Merged

Conversation

taveras
Copy link
Contributor

@taveras taveras commented Jan 8, 2018

This work enables a solid set of rules for linting the source code in the project.

Description

While this project is set up to use eslint for linting our JavaScript source code, it did not have any rules enabled to be checked against.

This work sets up eslint to use the Airbnb JavaScript Style Guide, and fixes issues to make the code adhere to these rules.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Related Issue

#23
#15

Motivation and Context

The project requires a solid base of eslint rules in which it should adhere.

How Has This Been Tested?

This was tested by running our linter and unit test suites, and ensured that all functionality remains.

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation (if required).
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Array.from(attributes)
.forEach(({ name, value }) => {
result[name] = value;
});
Copy link
Contributor

@pgoldrbx pgoldrbx Jan 8, 2018

Choose a reason for hiding this comment

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

Q: was this change for the linter? the reduce is a lot simpler to me personally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed, the results[name] = value; line triggered the no-param-reassign rule

if we add the transform-object-rest-spread babel plugin, we could instead write something like this:

return Array.from(attributes)
    .reduce((results, { name, value }) => {
      return {
        ...results,
        [name]: value
      };
    }, {});

alternatively, we could use Object.assign in a similar way 🤔
i'll come up with a more legible option

Copy link
Contributor

Choose a reason for hiding this comment

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

no i'm ok with your solution. no need! you can just move along

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 sounds good!

import React from 'react';
/* eslint-disable no-unused-expressions */

import { describe, it, before, beforeEach, after } from 'mocha';
Copy link
Contributor

Choose a reason for hiding this comment

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

these aren't accepted as globals using the airbnb styleguide? (i guess we can't target just .spec files in a config. that's a little annoying but i guess we'll live with it.

@@ -1,6 +1,10 @@
import React from 'react';
/* eslint-disable no-unused-expressions */
Copy link
Contributor

Choose a reason for hiding this comment

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

let's not disable rules. let's use the function form e.g. .to.equal(true) versus .to.be.true

@@ -10,92 +14,94 @@ import { visitNode } from '../src/helpers';
configure({ adapter: new Adapter() });

describe('XMLToReact class ', () => {
const TestComponent = ({ fancy, children }) => {
const classes = fancy ? 'test fancy' : 'test';
return React.createElement('div', { className: classes }, children);
Copy link
Contributor

Choose a reason for hiding this comment

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

trivial... you could name the variable className and save yourself a few characters ;)

.eslintrc.js Outdated
mocha: true,
browser: true,
node: true,
es6: true
Copy link
Contributor

Choose a reason for hiding this comment

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

do we reference anything browser-specific where we need to specify browser?
also, do we need es6 here in addition to ecmaVersion above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: browser, nope! i felt that adding it here may be safer if we ever need to start using globals in a browser environment, but we can always add it when necessary

re: es6, it seems to enable the same features as ecmaVersion with the exception of modules.

i'll leave mocha as the only environment

Copy link
Contributor

Choose a reason for hiding this comment

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

great!

Copy link
Contributor

@pgoldrbx pgoldrbx left a comment

Choose a reason for hiding this comment

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

a couple config questions but lgtm!

@taveras
Copy link
Contributor Author

taveras commented Jan 8, 2018

🚀 shipping, as all feedback has been addressed and this is looking safe to merge.

@taveras taveras merged commit 4ac5bcc into master Jan 8, 2018
@taveras taveras deleted the feat/linting branch January 8, 2018 19:56
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.

2 participants