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 eslint to the project #58

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dist/
docs/
examples/
node_modules/
lib/
scripts/
# for disable website but should be done as well
website/
*.md
90 changes: 90 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
parser: babel-eslint

plugins:
- react

env:
browser: true
node: true

globals:
__DEV__: true
# Jest / Jasmine
describe: false
xdescribe: false
beforeEach: false
afterEach: false
it: false
xit: false
jest: false
pit: false
expect: false
spyOn: false
jasmine: false

rules:
# ERRORS
space-before-blocks: 2
indent: [2, 2, {SwitchCase: 1}]
brace-style: 2
space-after-keywords: 2
strict: [2, global]
# Make this a warning for now. We do this in a few places so we might need to
# disable
dot-notation: 2
dot-location: [2, property]
quotes: [2, single, avoid-escape]
no-multi-spaces: 2

# WISHLIST. One day...
# We'll need a custom version of this that does a subset of the whole rule.
# Otherwise this is just too noisy.
# valid-jsdoc: 1
# Ideally, we could just warn when *new* lines are added that exceed 80 chars
# while not warning about existing ones (often URLs, etc. which are
# necessarily long), but we don't have a good way to do so.
# max-len: [0, 80]

# DISABLED. These aren't compatible with our style
# We use this for private/internal variables
no-underscore-dangle: 0
# We pass constructors around / access them from members
new-cap: 0
# We do this a lot.
no-use-before-define: 0
# We do this in a few places to align values
key-spacing: 0
# It's nice to be able to leave catch blocks empty
no-empty: 0
# It makes code more readable to make this explicit sometimes
no-undef-init: 0

# BROKEN. We'd like to turn these back on.
# causes a ton of noise, eslint is too picky?
block-scoped-var: 0

# JSX
# Our transforms set this automatically
react/display-name: 0
react/jsx-boolean-value: [2, always]
react/jsx-no-undef: 2
react/jsx-quotes: [2, double]
# We don't care to do this
react/jsx-sort-prop-types: 0
react/jsx-sort-props: 0
react/jsx-uses-react: 2
react/jsx-uses-vars: 2
# It's easier to test some things this way
react/no-did-mount-set-state: 0
react/no-did-update-set-state: 0
# We define multiple components in test files
react/no-multi-comp: 0
react/no-unknown-property: 2
# This isn't useful in our test code
react/prop-types: 0
react/react-in-jsx-scope: 2
react/self-closing-comp: 2
# We don't care to do this
react/sort-comp: 0
react/wrap-multilines: [2, {declaration: false, assignment: false}]
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
language: node_js
node_js:
- 'iojs-v3'
before_install:
- npm install -g npm@2
env:
- TEST_DIR=.
- TEST_DIR=scripts/babel-relay-plugin
Expand Down
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

/* eslint-disable */

'use strict';

var babel = require('gulp-babel');
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"scripts": {
"build": "[ $(ulimit -n) -lt 4096 ] && ulimit -n 4096; gulp",
"prepublish": "npm run build",
"lint": "eslint .",
"test": "npm run typecheck && NODE_ENV=test jest",
"typecheck": "flow check src/",
"update-schema": "babel-node ./scripts/jest/updateSchema.js"
Expand All @@ -36,10 +37,13 @@
},
"devDependencies": {
"babel-core": "5.8.21",
"babel-eslint": "^4.0.7",
"babel-loader": "5.3.2",
"babel-relay-plugin": "^0.1.2",
"del": "^1.2.0",
"envify": "^3.4.0",
"eslint": "^1.1.0",
"eslint-plugin-react": "^3.2.3",
"flow-bin": "0.14.0",
"graphql": "^0.2.6",
"gulp": "^3.9.0",
Expand Down
2 changes: 1 addition & 1 deletion src/container/__tests__/RelayRootContainer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ describe('RelayRootContainer', function() {

it('aborts loading requests', () => {
function mockLoading(request) {
request.block();
request.block();
}
expect(mockLoading).toAbortOnUpdate();
expect(mockLoading).toAbortOnUnmount();
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/query/GraphQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ class GraphQLMutation extends GraphQLOperation {
/**
* @return {number}
*/
getJSONType() {
getJSONType() {
return JSON_TYPES.MUTATION;
}
}
Expand Down Expand Up @@ -587,7 +587,7 @@ class GraphQLSubscription extends GraphQLOperation {
/**
* @return {number}
*/
getJSONType() {
getJSONType() {
return JSON_TYPES.SUBSCRIPTION;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/store/GraphQLRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ class GraphQLRange {
return range;
}

toJSON(){
toJSON() {
return [
this._hasFirst,
this._hasLast,
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/store/GraphQLSegment.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ class GraphQLSegment {
index +
' to (' +
this._minIndex +
", " +
', ' +
this._maxIndex +
")"
')'
);

return;
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/store/__mocks__/generateClientID.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
var count = 1;

var generateClientID = jest.genMockFunction().mockImplementation(
() => { return 'client:' + count++;}
() => 'client:' + count++
);

module.exports = generateClientID;
4 changes: 2 additions & 2 deletions src/legacy/store/__tests__/GraphQLFragmentPointer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('GraphQLFragmentPointer', () => {
});

it('throws when creating a singular pointer with multiple IDs', () => {
expect(() =>{
expect(() => {
new GraphQLFragmentPointer(['123'], singularFragment);
}).toFailInvariant(
'GraphQLFragmentPointer: Wrong plurality, array of data IDs ' +
Expand All @@ -164,7 +164,7 @@ describe('GraphQLFragmentPointer', () => {
});

it('throws when creating a plural pointer with a single ID', () => {
expect(() =>{
expect(() => {
new GraphQLFragmentPointer('123', pluralFragment);
}).toFailInvariant(
'GraphQLFragmentPointer: Wrong plurality, single data ID supplied ' +
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/store/__tests__/GraphQLSegment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ describe('GraphQLSegment', () => {
it('rolls back bumped edges from failed concatSegment operations', () => {
console.error = jest.genMockFunction();
segment.addEdgesAfterCursor(edges.slice(0, 2), null);
expect(segment.__debug().idToIndices['edge2'].length).toBe(1);
expect(segment.__debug().idToIndices.edge2.length).toBe(1);

var otherSegment = new GraphQLSegment();
var edge2 = edges.slice(1, 2);
Expand All @@ -286,7 +286,7 @@ describe('GraphQLSegment', () => {
'edge2'
);
// Make sure it rolled back the deleted edge from indices map
expect(segment.__debug().idToIndices['edge2'].length).toBe(1);
expect(segment.__debug().idToIndices.edge2.length).toBe(1);
});

it('should check for valid id in segment', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/store/generateClientEdgeID.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @internal
*/
function generateClientEdgeID(rangeID: string, nodeID: string): string {
return 'client:' + rangeID + ':' + nodeID;
return 'client:' + rangeID + ':' + nodeID;
}

module.exports = generateClientEdgeID;
4 changes: 3 additions & 1 deletion src/mutation/RelayMutationTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ class RelayMutationTransaction {
var shouldRollback = true;
var commitFailureCallback = this._onCommitFailureCallback;
if (commitFailureCallback) {
var preventAutoRollback = function() { shouldRollback = false; };
var preventAutoRollback = function() {
shouldRollback = false;
};
ErrorUtils.applyWithGuard(
commitFailureCallback,
null,
Expand Down
Loading