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
-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!');
}