ソースを参照

Add some ESLint rules and fix some related issues

Maxime Quandalle 9 年 前
コミット
944a1065d3
5 ファイル変更46 行追加42 行削除
  1. 32 26
      .eslintrc
  2. 1 0
      .travis.yml
  3. 2 4
      client/components/lists/listHeader.js
  4. 4 4
      client/lib/accessibility.js
  5. 7 8
      models/import.js

+ 32 - 26
.eslintrc

@@ -2,41 +2,46 @@ ecmaFeatures:
   experimentalObjectRestSpread: true
   experimentalObjectRestSpread: true
 
 
 rules:
 rules:
-  accessor-pairs: [2]
-  consistent-return: [2]
+  accessor-pairs: 2
+  comma-dangle: [2, 'always-multiline']
+  consistent-return: 2
+  dot-notation: 2
+  eqeqeq: 2
   indent: [2, 2]
   indent: [2, 2]
-  semi: [2, always]
-  comma-dangle: [2, always-multiline]
+  no-cond-assign: 2
+  no-constant-condition: 2
+  no-eval: 2
   no-inner-declarations: [0]
   no-inner-declarations: [0]
-  dot-notation: [2]
-  eqeqeq: [2]
-  no-eval: [2]
-  radix: [2]
+  no-unneeded-ternary: 2
+  radix: 2
+  semi: [2, always]
 
 
   # Stylistic Issues
   # Stylistic Issues
-  camelcase: [2]
-  comma-spacing: [2]
-  comma-style: [2]
-  new-parens: [2]
-  no-lonely-if: [2]
-  no-multiple-empty-lines: [2]
-  no-nested-ternary: [2]
+  camelcase: 2
+  comma-spacing: 2
+  comma-style: 2
   linebreak-style: [2, unix]
   linebreak-style: [2, unix]
+  new-parens: 2
+  no-lonely-if: 2
+  no-multiple-empty-lines: 2
+  no-nested-ternary: 2
+  no-spaced-func: 2
+  operator-linebreak: 2
   quotes: [2, single]
   quotes: [2, single]
-  semi-spacing: [2]
+  semi-spacing: 2
+  space-unary-ops: 2
   spaced-comment: [2, always, markers: ['/']]
   spaced-comment: [2, always, markers: ['/']]
-  space-unary-ops: [2]
 
 
   # ECMAScript 6
   # ECMAScript 6
-  arrow-parens: [2]
-  arrow-spacing: [2]
-  no-class-assign: [2]
-  no-dupe-class-members: [2]
-  no-var: [2]
-  object-shorthand: [2]
-  prefer-const: [2]
-  prefer-template: [2]
-  prefer-spread: [2]
+  arrow-parens: 2
+  arrow-spacing: 2
+  no-class-assign: 2
+  no-dupe-class-members: 2
+  no-var: 2
+  object-shorthand: 2
+  prefer-const: 2
+  prefer-spread: 2
+  prefer-template: 2
 
 
 globals:
 globals:
   # Meteor globals
   # Meteor globals
@@ -78,6 +83,7 @@ globals:
   FS: false
   FS: false
   getSlug: false
   getSlug: false
   Migrations: false
   Migrations: false
+  moment: false
   Mousetrap: false
   Mousetrap: false
   Picker: false
   Picker: false
   Presence: true
   Presence: true

+ 1 - 0
.travis.yml

@@ -4,5 +4,6 @@ node_js:
   - "0.10.40"
   - "0.10.40"
 install:
 install:
   - "npm install -g eslint"
   - "npm install -g eslint"
+  - "npm install -g eslint-plugin-meteor"
 script:
 script:
   - "eslint ./"
   - "eslint ./"

+ 2 - 4
client/components/lists/listHeader.js

@@ -62,14 +62,12 @@ BlazeComponent.extendComponent({
         try {
         try {
           trelloCard = JSON.parse(jsonData);
           trelloCard = JSON.parse(jsonData);
         } catch (e) {
         } catch (e) {
-          console.log(e);
           this.setError('error-json-malformed');
           this.setError('error-json-malformed');
           return;
           return;
         }
         }
         Meteor.call('importTrelloCard', trelloCard, this.currentData()._id, sortIndex,
         Meteor.call('importTrelloCard', trelloCard, this.currentData()._id, sortIndex,
           (error, response) => {
           (error, response) => {
             if (error) {
             if (error) {
-              console.log(error);
               this.setError(error.error);
               this.setError(error.error);
             } else {
             } else {
               Filter.addException(response);
               Filter.addException(response);
@@ -77,8 +75,8 @@ BlazeComponent.extendComponent({
             }
             }
           }
           }
         );
         );
-      }
-    },];
+      },
+    }];
   },
   },
 
 
   onCreated() {
   onCreated() {

+ 4 - 4
client/lib/accessibility.js

@@ -7,7 +7,7 @@
 // Without an href, links are non-keyboard-focusable and are not presented on
 // Without an href, links are non-keyboard-focusable and are not presented on
 // blind screen readers. We default to the empty anchor `#` href.
 // blind screen readers. We default to the empty anchor `#` href.
 function enforceHref(attributes) {
 function enforceHref(attributes) {
-  if (! _.has(attributes, 'href')) {
+  if (!_.has(attributes, 'href')) {
     attributes.href = '#';
     attributes.href = '#';
   }
   }
   return attributes;
   return attributes;
@@ -17,7 +17,7 @@ function enforceHref(attributes) {
 // presented by screen readers. `aria-label`, on the other hand, is specific to
 // presented by screen readers. `aria-label`, on the other hand, is specific to
 // accessibility and is presented in ways that title shouldn't be.
 // accessibility and is presented in ways that title shouldn't be.
 function copyTitleInAriaLabel(attributes) {
 function copyTitleInAriaLabel(attributes) {
-  if (! _.has(attributes, 'aria-label') && _.has(attributes, 'title')) {
+  if (!_.has(attributes, 'aria-label') && _.has(attributes, 'title')) {
     attributes['aria-label'] = attributes.title;
     attributes['aria-label'] = attributes.title;
   }
   }
   return attributes;
   return attributes;
@@ -34,8 +34,8 @@ const {
 
 
 HTML.A = (attributes, ...others) => {
 HTML.A = (attributes, ...others) => {
   return superA(copyTitleInAriaLabel(enforceHref(attributes)), ...others);
   return superA(copyTitleInAriaLabel(enforceHref(attributes)), ...others);
-}
+};
 
 
 HTML.I = (attributes, ...others) => {
 HTML.I = (attributes, ...others) => {
   return superI(copyTitleInAriaLabel(attributes), ...others);
   return superI(copyTitleInAriaLabel(attributes), ...others);
-}
+};

+ 7 - 8
models/import.js

@@ -1,7 +1,7 @@
 Meteor.methods({
 Meteor.methods({
   importTrelloCard(trelloCard, listId, sortIndex) {
   importTrelloCard(trelloCard, listId, sortIndex) {
     // 1. check parameters are ok from a syntax point of view
     // 1. check parameters are ok from a syntax point of view
-    DateString = Match.Where(function (dateAsString) {
+    const DateString = Match.Where(function (dateAsString) {
       check(dateAsString, String);
       check(dateAsString, String);
       return moment(dateAsString, moment.ISO_8601).isValid();
       return moment(dateAsString, moment.ISO_8601).isValid();
     });
     });
@@ -25,9 +25,6 @@ Meteor.methods({
       check(listId, String);
       check(listId, String);
       check(sortIndex, Number);
       check(sortIndex, Number);
     } catch(e) {
     } catch(e) {
-      if(Meteor.isServer) {
-        console.log(e);
-      }
       throw new Meteor.Error('error-json-schema');
       throw new Meteor.Error('error-json-schema');
     }
     }
 
 
@@ -59,7 +56,9 @@ Meteor.methods({
     };
     };
 
 
     // 4. find actual creation date
     // 4. find actual creation date
-    const creationAction = trelloCard.actions.find((action) => {return action.type === 'createCard';});
+    const creationAction = trelloCard.actions.find((action) => {
+      return action.type === 'createCard';
+    });
     if(creationAction) {
     if(creationAction) {
       cardToCreate.createdAt = creationAction.date;
       cardToCreate.createdAt = creationAction.date;
     }
     }
@@ -92,7 +91,7 @@ Meteor.methods({
     Activities.direct.insert({
     Activities.direct.insert({
       activityType: 'importCard',
       activityType: 'importCard',
       boardId: cardToCreate.boardId,
       boardId: cardToCreate.boardId,
-      cardId: cardId,
+      cardId,
       createdAt: dateOfImport,
       createdAt: dateOfImport,
       listId: cardToCreate.listId,
       listId: cardToCreate.listId,
       source: {
       source: {
@@ -109,7 +108,7 @@ Meteor.methods({
       if(currentAction.type === 'commentCard') {
       if(currentAction.type === 'commentCard') {
         const commentToCreate = {
         const commentToCreate = {
           boardId: list.boardId,
           boardId: list.boardId,
-          cardId: cardId,
+          cardId,
           createdAt: currentAction.date,
           createdAt: currentAction.date,
           text: currentAction.data.text,
           text: currentAction.data.text,
           // XXX use the original comment user instead
           // XXX use the original comment user instead
@@ -120,7 +119,7 @@ Meteor.methods({
           activityType: 'addComment',
           activityType: 'addComment',
           boardId: commentToCreate.boardId,
           boardId: commentToCreate.boardId,
           cardId: commentToCreate.cardId,
           cardId: commentToCreate.cardId,
-          commentId: commentId,
+          commentId,
           createdAt: commentToCreate.createdAt,
           createdAt: commentToCreate.createdAt,
           userId: commentToCreate.userId,
           userId: commentToCreate.userId,
         });
         });