Try out eslint v9

This commit is contained in:
Dragon Fire
2024-04-06 17:43:07 -04:00
parent 1580de3191
commit ac0cfc00a1
12 changed files with 32 additions and 149 deletions
+3 -3
View File
@@ -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
+8 -15
View File
@@ -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:**
-1
View File
@@ -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'],
-1
View File
@@ -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",
-26
View File
@@ -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\`\`\``);
}
};
-38
View File
@@ -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);
}
};
-49
View File
@@ -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.');
}
};
@@ -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'],
@@ -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'],
+1 -1
View File
@@ -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!');
}
+14
View File
@@ -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
}
}
];
+4 -13
View File
@@ -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"
}
}