#20 Add eslint to prettier

Closed
alex wants to merge 2 commits from alex/eslint-prettier into alex/prettier
9 changed files with 966 additions and 24 deletions
  1. 3 5
      core/battle/ai.js
  2. 0 2
      core/battle/index.js
  3. 1 2
      core/character/index.js
  4. 0 2
      core/character/party.js
  5. 1 2
      core/config.js
  6. 1 3
      core/game.js
  7. 1 0
      core/util/typecheck.js
  8. 947 7
      package-lock.json
  9. 12 1
      package.json

+ 3 - 5
core/battle/ai.js

@@ -1,7 +1,5 @@
-const Move = require('./move')
-
-const discord = require('discord.js')
 const _ = require('lodash')
+const Move = require('./move')
 const prompt = require('../util/prompt')
 
 // The base class! Each method is called to request a decision from the AI.
@@ -14,7 +12,7 @@ class AI {
   }
 
   // Returns { move: Move, targets: [Character] } to perform next.
-  async moveChoice(self, battle) {}
+  async moveChoice() {}
 }
 
 // For player-controlled characters. Interfaces with Discord.
@@ -101,7 +99,7 @@ class DiscordAI extends AI {
       title: this.char.getName(this.battle.game.guild),
       description: targetPromptDesc,
       choices: await Promise.all(
-        targetable.map(async (char, i) => ({
+        targetable.map(async char => ({
           emote: await char.getEmote(this.battle.game),
           name: char.getName(this.battle.game.guild),
           char,

+ 0 - 2
core/battle/index.js

@@ -1,9 +1,7 @@
 // Note: Battles are *not* database-backed.
 
-const discord = require('discord.js')
 const _ = require('lodash')
 const time = require('../util/time')
-const Party = require('../character/party')
 
 class Battle {
   constructor(game) {

+ 1 - 2
core/character/index.js

@@ -1,6 +1,5 @@
 const {Document} = require('camo')
 const battleAIs = require('../battle/ai')
-const Move = require('../battle/move')
 const log = require('../util/log')
 
 const gm = require('gm')
@@ -152,7 +151,7 @@ class Character extends Document {
       party = await Party.of([this])
     }
 
-    return party || (await Party.findOne({_id: this.partyID}))
+    return party || Party.findOne({_id: this.partyID})
   }
 }
 

+ 0 - 2
core/character/party.js

@@ -1,8 +1,6 @@
 const {Document} = require('camo')
 const Character = require('./character')
-
 const tinycolor = require('tinycolor2')
-const chalk = require('chalk')
 
 // Just an organised party (read: team, group) of Characters.
 class Party extends Document {

+ 1 - 2
core/config.js

@@ -1,11 +1,10 @@
-const path = require('path')
 const fs = require('mz/fs')
 const json = require('comment-json')
 const typecheck = require('./util/typecheck')
 
 class Config {
   async load() {
-    const jsonStr = await fs.readFile('config.json', 'utf8').catch(err => {
+    const jsonStr = await fs.readFile('config.json', 'utf8').catch(() => {
       // Make the error more human-friendly
       return Promise.reject('Could not read config.json file')
     })

+ 1 - 3
core/game.js

@@ -11,8 +11,6 @@ const EmoteStore = require('./stores/emote')
 const Character = require('./character')
 const Battle = require('./battle/battle')
 const Move = require('./battle/move')
-const Party = require('./character/party')
-const {DiscordAI} = require('./battle/ai')
 
 class Game {
   // Starts the game. Should only run once per process!
@@ -226,7 +224,7 @@ class Game {
 
       // Usage: .emote @user#0001 @user#0002 [...]
       if (msg.content.startsWith('.emote ')) {
-        for (const [userID, user] of msg.mentions.users) {
+        for (const [userID] of msg.mentions.users) {
           const char = await Character.findOne({discordID: userID})
           const emote = await char.getEmote(this)
 

+ 1 - 0
core/util/typecheck.js

@@ -48,6 +48,7 @@ module.exports = (val, schema, postfix = '') => {
     throw new TypeError(`Typecheck failed: one of ${choices} ${postfix}`)
   }
 
+  let reason
   if (validation && (reason = validation()) === false) {
     throw new TypeError(`Typecheck failed: ${reason} ${postfix}`)
   }

File diff suppressed because it is too large
+ 947 - 7
package-lock.json


+ 12 - 1
package.json

@@ -3,7 +3,14 @@
   "repository": "https://notabug.org/alex/antipath",
   "license": "AGPL-3.0-or-later",
   "scripts": {
-    "prettier": "prettier --write '**/*.js'"
+    "lint": "eslint .",
+    "prettier": "eslint . --fix"
+  },
+  "eslintConfig": {
+    "extends": [
+      "@nanalan",
+      "plugin:prettier/recommended"
+    ]
   },
   "prettier": {
     "semi": false,
@@ -32,6 +39,10 @@
     "nedb": "^1.8.0"
   },
   "devDependencies": {
+    "@nanalan/eslint-config": "^1.0.0",
+    "eslint": "^5.6.1",
+    "eslint-config-prettier": "^3.1.0",
+    "eslint-plugin-prettier": "^2.7.0",
     "prettier": "^1.14.3"
   }
 }