From ac0cfc00a11d6b669bcf52ab1e567a6a50dedeb8 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 6 Apr 2024 17:43:07 -0400 Subject: [PATCH] Try out eslint v9 --- .github/workflows/test.yml | 6 ++-- README.md | 23 +++++--------- Xiao.js | 1 - assets/json/logos.json | 1 - commands/code/beautify.js | 26 --------------- commands/code/lint-rule.js | 38 ---------------------- commands/code/lint.js | 49 ----------------------------- commands/{code => search}/github.js | 2 +- commands/{code => search}/npm.js | 2 +- commands/util/generate-credit.js | 2 +- eslint.config.js | 14 +++++++++ package.json | 17 +++------- 12 files changed, 32 insertions(+), 149 deletions(-) delete mode 100644 commands/code/beautify.js delete mode 100644 commands/code/lint-rule.js delete mode 100644 commands/code/lint.js rename commands/{code => search}/github.js (99%) rename commands/{code => search}/npm.js (99%) create mode 100644 eslint.config.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ac76eaa..8f5cf8f7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,11 +16,11 @@ jobs: - name: Install NPM v6 (latest installs all packages) run: npm install -g npm@6 - - name: Install ESLint v8 - run: npm install -g eslint@8 + - name: Install ESLint v9 + run: npm install -g eslint@9 - name: Install ESLint Configs and Plugins - run: npm install eslint-config-amber eslint-plugin-json + run: npm install @eslint/js@9 eslint-config-amber eslint-plugin-jsonc - name: Run ESLint run: npm test diff --git a/README.md b/README.md index 1554deae..9903e12e 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Just read `LICENSE.md`. Give credit if you use any part of this monster, thanks. 22. Run `pm2 start Xiao.js --name xiao` to run the bot. ## Commands -Total: 512 +Total: 510 ### Utility: @@ -232,6 +232,7 @@ Total: 512 * **anime-staff:** Searches AniList for your query, getting staff results. * **define:** Defines a word. * **frinkiac:** Input a line from the Simpsons to get the episode/season. +* **github:** Responds with information on a GitHub repository. * **google-autofill:** Responds with a list of the Google Autofill results for a particular query. * **gravatar:** Responds with the Gravatar for an email. * **http-cat:** Responds with a cat for an HTTP status code. @@ -241,6 +242,7 @@ Total: 512 * **nasa:** Searches NASA's image archive for your query. * **neopet:** Responds with the image of a specific Neopet. * **neopets-item:** Responds with information on a specific Neopets item. +* **npm:** Responds with information on an NPM package. * **periodic-table:** Finds an element on the periodic table. * **rule:** Responds with a rule of the internet. * **urban:** Defines a word, but with Urban Dictionary. @@ -286,14 +288,6 @@ Total: 512 * **valid-url:** Tests whether a URL is valid or not. * **zodiac-sign:** Responds with the Zodiac Sign for the given month/day. -### Programming: - -* **beautify:** Beautifies code with js-beautify. -* **github:** Responds with information on a GitHub repository. -* **lint:** Lints code using ESLint. -* **lint-rule:** Responds with information on an ESLint rule. -* **npm:** Responds with information on an NPM package. - ### Single-Player Games: * **20-questions:** Think of something and 20Q will read your mind by asking a few simple questions. @@ -665,7 +659,6 @@ Total: 512 * [discord.js](https://www.npmjs.com/package/discord.js) * [dotenv](https://www.npmjs.com/package/dotenv) * [emoji-regex](https://www.npmjs.com/package/emoji-regex) -* [eslint](https://www.npmjs.com/package/eslint) * [fen-validator](https://www.npmjs.com/package/fen-validator) * [font-finder](https://www.npmjs.com/package/font-finder) * [gifencoder](https://www.npmjs.com/package/gifencoder) @@ -673,7 +666,6 @@ Total: 512 * [html-entities](https://www.npmjs.com/package/html-entities) * [image-to-ascii](https://www.npmjs.com/package/image-to-ascii) * [ioredis](https://www.npmjs.com/package/ioredis) -* [js-beautify](https://www.npmjs.com/package/js-beautify) * [js-chess-engine](https://www.npmjs.com/package/js-chess-engine) * [jszip](https://www.npmjs.com/package/jszip) * [kuroshiro](https://www.npmjs.com/package/kuroshiro) @@ -706,6 +698,7 @@ Total: 512 * [ytdl-core](https://www.npmjs.com/package/ytdl-core) * [zip-to-timezone](https://www.npmjs.com/package/zip-to-timezone) * [zlib-sync](https://www.npmjs.com/package/zlib-sync) + ### Other Credits * **changelog:** - [GitHub](https://github.com/) (API) @@ -865,6 +858,8 @@ Total: 512 - [Merriam-Webster's Collegiate® Dictionary](https://www.merriam-webster.com/) (API) * **frinkiac:** - [Frinkiac](https://frinkiac.com/) (API) +* **github:** + - [GitHub](https://github.com/) (API) * **google-autofill:** - [Google](https://www.google.com/) (Autofill API) * **gravatar:** @@ -886,6 +881,8 @@ Total: 512 * **neopets-item:** - [Neopets](http://www.neopets.com/) (Original Game) - [JellyNeo Item Database](https://items.jellyneo.net/) (Item Data) +* **npm:** + - [npm](https://www.npmjs.com/) (API) * **periodic-table:** - [Bowserinator](https://github.com/Bowserinator/) (Periodic Table Data) - [Google](https://www.google.com/) (Noto Font) @@ -961,10 +958,6 @@ Total: 512 - [Hasbro](https://shop.hasbro.com/en-us) (Original "Scrabble" Game) * **screenshot:** - [Thum.io](https://www.thum.io/) (API) -* **github:** - - [GitHub](https://github.com/) (API) -* **npm:** - - [npm](https://www.npmjs.com/) (API) * **20-questions:** - [20Q.net](http://20q.net/) (API) * **akinator:** diff --git a/Xiao.js b/Xiao.js index 08308ff3..1e583971 100644 --- a/Xiao.js +++ b/Xiao.js @@ -47,7 +47,6 @@ client.registry ['search', 'Search'], ['pokedex', 'Pokédex'], ['analyze', 'Analyzers'], - ['code', 'Programming'], ['games-sp', 'Single-Player Games'], ['games-mp', 'Multi-Player Games'], ['edit-face', 'Face Manipulation'], diff --git a/assets/json/logos.json b/assets/json/logos.json index eff9721b..7dfefb49 100644 --- a/assets/json/logos.json +++ b/assets/json/logos.json @@ -1,6 +1,5 @@ { "github": "https://i.imgur.com/e4HunUm.png", - "eslint": "https://i.imgur.com/04GhEhU.png", "npm": "https://i.imgur.com/ErKf5Y0.png", "googleTranslate": "https://i.imgur.com/h3RoHyp.png", "nasa": "https://i.imgur.com/Wh8jY9c.png", diff --git a/commands/code/beautify.js b/commands/code/beautify.js deleted file mode 100644 index d054779c..00000000 --- a/commands/code/beautify.js +++ /dev/null @@ -1,26 +0,0 @@ -const Command = require('../../framework/Command'); -const { js_beautify: beautify } = require('js-beautify'); - -module.exports = class BeautifyCommand extends Command { - constructor(client) { - super(client, { - name: 'beautify', - aliases: ['js-beautify'], - group: 'code', - memberName: 'beautify', - description: 'Beautifies code with js-beautify.', - clientPermissions: ['READ_MESSAGE_HISTORY'], - args: [ - { - key: 'code', - type: 'code' - } - ] - }); - } - - run(msg, { code }) { - if (code.lang && code.lang !== 'js') return msg.reply('I can only beautify JavaScript.'); - return msg.reply(`\`\`\`js\n${beautify(code.code)}\n\`\`\``); - } -}; diff --git a/commands/code/lint-rule.js b/commands/code/lint-rule.js deleted file mode 100644 index 8fe55924..00000000 --- a/commands/code/lint-rule.js +++ /dev/null @@ -1,38 +0,0 @@ -const Command = require('../../framework/Command'); -const { MessageEmbed } = require('discord.js'); -const logos = require('../../assets/json/logos'); -const { Linter } = require('eslint'); -const linter = new Linter(); -const rules = linter.getRules(); - -module.exports = class LintRuleCommand extends Command { - constructor(client) { - super(client, { - name: 'lint-rule', - aliases: ['eslint-rule', 'linter-rule'], - group: 'code', - memberName: 'lint-rule', - description: 'Responds with information on an ESLint rule.', - clientPermissions: ['EMBED_LINKS'], - args: [ - { - key: 'rule', - type: 'string', - parse: rule => rule.toLowerCase().replaceAll(' ', '-') - } - ] - }); - } - - run(msg, { rule }) { - if (!rules.has(rule)) return msg.say('Could not find any results.'); - const data = rules.get(rule).meta; - const embed = new MessageEmbed() - .setAuthor('ESLint', logos.eslint, 'https://eslint.org/') - .setColor(0x3A33D1) - .setTitle(rule) - .setURL(data.docs.url) - .setDescription(data.docs.description); - return msg.embed(embed); - } -}; diff --git a/commands/code/lint.js b/commands/code/lint.js deleted file mode 100644 index e5c3a9d0..00000000 --- a/commands/code/lint.js +++ /dev/null @@ -1,49 +0,0 @@ -const Command = require('../../framework/Command'); -const { Linter } = require('eslint'); -const linter = new Linter(); -const { stripIndents } = require('common-tags'); -const { trimArray } = require('../../util/Util'); -const { goodMessages, badMessages, defaultConfig } = require('../../assets/json/lint'); - -module.exports = class LintCommand extends Command { - constructor(client) { - super(client, { - name: 'lint', - aliases: ['eslint', 'linter'], - group: 'code', - memberName: 'lint', - description: 'Lints code using ESLint.', - clientPermissions: ['READ_MESSAGE_HISTORY'], - args: [ - { - key: 'code', - type: 'code' - } - ] - }); - } - - run(msg, { code }) { - if (!code.lang || ['js', 'javascript'].includes(code.lang)) { - const errors = linter.verify(code.code, defaultConfig); - if (!errors.length) return msg.reply(goodMessages[Math.floor(Math.random() * goodMessages.length)]); - const errorMap = trimArray(errors.map(err => `\`[${err.line}:${err.column}] ${err.message}\``)); - return msg.reply(stripIndents` - ${badMessages[Math.floor(Math.random() * badMessages.length)]} - ${errorMap.join('\n')} - `); - } - if (code.lang === 'json') { - try { - JSON.parse(code.code); - return msg.reply(goodMessages[Math.floor(Math.random() * goodMessages.length)]); - } catch (err) { - return msg.reply(stripIndents` - ${badMessages[Math.floor(Math.random() * badMessages.length)]} - \`${err.name}: ${err.message}\` - `); - } - } - return msg.reply('I don\'t know how to lint that language.'); - } -}; diff --git a/commands/code/github.js b/commands/search/github.js similarity index 99% rename from commands/code/github.js rename to commands/search/github.js index 0feb419e..9bc42106 100644 --- a/commands/code/github.js +++ b/commands/search/github.js @@ -11,7 +11,7 @@ module.exports = class GithubCommand extends Command { super(client, { name: 'github', aliases: ['repo', 'gh', 'github-repo', 'gh-repo'], - group: 'code', + group: 'search', memberName: 'github', description: 'Responds with information on a GitHub repository.', clientPermissions: ['EMBED_LINKS'], diff --git a/commands/code/npm.js b/commands/search/npm.js similarity index 99% rename from commands/code/npm.js rename to commands/search/npm.js index 2fe67b16..31d43545 100644 --- a/commands/code/npm.js +++ b/commands/search/npm.js @@ -9,7 +9,7 @@ module.exports = class NPMCommand extends Command { constructor(client) { super(client, { name: 'npm', - group: 'code', + group: 'search', memberName: 'npm', description: 'Responds with information on an NPM package.', clientPermissions: ['EMBED_LINKS'], diff --git a/commands/util/generate-credit.js b/commands/util/generate-credit.js index 622f19ed..c607d130 100644 --- a/commands/util/generate-credit.js +++ b/commands/util/generate-credit.js @@ -32,7 +32,7 @@ module.exports = class GenerateCreditCommand extends Command { }).join('\n'); }) .filter(cmds => cmds); - const file = Buffer.from(`## Credits\n### NPM Packages\n${npm}\n### Other Credits\n${list.join('\n')}`); + const file = Buffer.from(`## Credits\n### NPM Packages\n${npm}\n\n### Other Credits\n${list.join('\n')}`); await msg.direct({ files: [{ attachment: file, name: 'credits.txt' }] }); return msg.say('📬 Sent `credits.txt` to your DMs!'); } diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..705ccd00 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,14 @@ +const { default: eslintPluginJsonc } = require('eslint-plugin-jsonc'); +const { default: js } = require('@eslint/js'); +const amber = require('eslint-config-amber'); + +module.exports = [ + ...eslintPluginJsonc.configs['flat/recommended-with-json'], + { + files: ['**/*.js'], + rules: { + ...js.configs.recommended.rules, + ...amber.rules + } + } +]; diff --git a/package.json b/package.json index d86eb17e..73098924 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "private": true, "scripts": { "test": "npm run lint", - "lint": "eslint . --ext .js --ext .json", + "lint": "eslint .", "start": "node Xiao.js" }, "repository": { @@ -50,7 +50,6 @@ "discord.js": "^13.17.1", "dotenv": "^16.4.5", "emoji-regex": "^10.3.0", - "eslint": "^8.57.0", "fen-validator": "^2.0.1", "font-finder": "^1.1.0", "gifencoder": "^2.0.1", @@ -58,7 +57,6 @@ "html-entities": "^2.5.2", "image-to-ascii": "^3.2.0", "ioredis": "^5.3.2", - "js-beautify": "^1.15.1", "js-chess-engine": "^1.0.2", "jszip": "^3.10.1", "kuroshiro": "^1.2.0", @@ -96,16 +94,9 @@ "zlib-sync": "^0.1.9" }, "devDependencies": { + "@eslint/js": "^9.0.0", + "eslint": "^9.0.0", "eslint-config-amber": "^2.0.4", - "eslint-plugin-json": "^3.1.0" - }, - "eslintConfig": { - "extends": [ - "amber", - "plugin:json/recommended" - ], - "plugins": [ - "json" - ] + "eslint-plugin-jsonc": "^2.15.0" } }