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 17 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
92 changes: 92 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
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
eol-last: 2
dot-notation: 2
dot-location: [2, property]
no-unused-vars: [2, args: none]
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 @@ -37,10 +38,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/__forks__/interface/RelayConnectionInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ var RelayConnectionInterface = {
},
};

module.exports = RelayConnectionInterface;
module.exports = RelayConnectionInterface;
Copy link
Contributor

Choose a reason for hiding this comment

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

We cannot accept this PR if there are changes to the src/ directory - rules should lenient enough to allow the code to pass as-is.

1 change: 0 additions & 1 deletion src/__forks__/traversal/printRelayQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

'use strict';

import type {Call} from 'RelayInternalTypes';
var RelayProfiler = require('RelayProfiler');
var RelayQuery = require('RelayQuery');

Expand Down
8 changes: 0 additions & 8 deletions src/container/__tests__/RelayContainer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ describe('RelayContainer', function() {
var React;
var ReactTestUtils;
var Relay;
var RelayMetaRoute;
var RelayQuery;
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, we sincerely appreciate your effort in making these fixes, but we can't accept the PR unless there are zero changes to files in src/.

var RelayRoute;

var toGraphQL;

var MockContainer;
var MockComponent;
var RelayTestRenderer;
Expand All @@ -52,12 +49,9 @@ describe('RelayContainer', function() {
React = require('React');
ReactTestUtils = require('ReactTestUtils');
Relay = require('Relay');
RelayMetaRoute = require('RelayMetaRoute');
RelayQuery = require('RelayQuery');
RelayRoute = require('RelayRoute');

toGraphQL = require('toGraphQL');

var render = jest.genMockFunction().mockImplementation(function() {
// Make it easier to expect prop values.
render.mock.calls[render.mock.calls.length - 1].props = this.props;
Expand Down Expand Up @@ -213,7 +207,6 @@ describe('RelayContainer', function() {
});

describe('conditional fragments', () => {
var sideshowFragment;
var MockFeed;
var feedFragment;

Expand All @@ -227,7 +220,6 @@ describe('RelayContainer', function() {
`
}
});
sideshowFragment = new GraphQL.QueryFragment('Test', 'Viewer');
feedFragment =
new GraphQL.QueryFragment('Test', 'Viewer', [
new GraphQL.Field('newsFeed'),
Expand Down
4 changes: 1 addition & 3 deletions src/container/__tests__/RelayRootContainer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('RelayRootContainer', function() {
var RelayRootContainer;
var RelayRoute;
var RelayStore;
var RelayTypes;

var ReactComponent;
var RelayContainer;
Expand All @@ -44,7 +43,6 @@ describe('RelayRootContainer', function() {
RelayRootContainer = require('RelayRootContainer');
RelayRoute = require('RelayRoute');
RelayStore = require('RelayStore');
RelayTypes = require('RelayTypes');

ReactComponent = React.createClass({render: () => <div />});
RelayContainer = Relay.createContainer(ReactComponent, {
Expand Down Expand Up @@ -391,7 +389,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
1 change: 0 additions & 1 deletion src/legacy/store/GraphQLStoreQueryResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import type RelayQuery from 'RelayQuery';
var RelayStoreData = require('RelayStoreData');
import type {StoreReaderData} from 'RelayTypes';

var invariant = require('invariant');
var filterExclusiveKeys = require('filterExclusiveKeys');
var readRelayQueryData = require('readRelayQueryData');
var recycleNodesInto = require('recycleNodesInto');
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;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('GraphQLDeferredQueryTracker', () => {
var RelayStoreData;

var flattenSplitRelayQueries;
var getWeakIdForObject;
var splitDeferredRelayQueries;

var {defer, getNode} = RelayTestUtils;
Expand All @@ -41,7 +40,6 @@ describe('GraphQLDeferredQueryTracker', () => {
RelayStoreData = require('RelayStoreData');

flattenSplitRelayQueries = require('flattenSplitRelayQueries');
getWeakIdForObject = require('getWeakIdForObject');
splitDeferredRelayQueries = require('splitDeferredRelayQueries');

recordStore = RelayStoreData.getDefaultInstance().getRecordStore();
Expand Down
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
2 changes: 0 additions & 2 deletions src/legacy/store/__tests__/GraphQLRange-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ var last5Edges = [edge96, edge97, edge98, edge99, edge100];
describe('GraphQLRange', () => {
var GraphQLRange;
var GraphQLStoreDataHandler;
var GraphQL;
var RelayConnectionInterface;

var origConsoleError;
Expand All @@ -87,7 +86,6 @@ describe('GraphQLRange', () => {
origConsoleWarn = console.warn;

GraphQLRange = require('GraphQLRange');
GraphQL = require('GraphQL');
GraphQLStoreDataHandler = require('GraphQLStoreDataHandler');
RelayConnectionInterface = require('RelayConnectionInterface');

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;
1 change: 0 additions & 1 deletion src/mutation/RelayMutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
'use strict';

import type GraphQL from 'GraphQL';
import type GraphQLFragmentPointer from 'GraphQLFragmentPointer';
var RelayDeprecated = require('RelayDeprecated');
var RelayFragmentReference = require('RelayFragmentReference');
import type RelayMetaRoute from 'RelayMetaRoute';
Expand Down
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
2 changes: 0 additions & 2 deletions src/mutation/__tests__/RelayMutation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jest
describe('RelayMutation', function() {
var MockMutation;
var Relay;
var RelayQuery;

var buildRQL;
var fromGraphQL;
Expand All @@ -34,7 +33,6 @@ describe('RelayMutation', function() {
jest.resetModuleRegistry();

Relay = require('Relay');
RelayQuery = require('RelayQuery');

buildRQL = require('buildRQL');
fromGraphQL = require('fromGraphQL');
Expand Down
Loading