Skip to content

Commit 14bc82f

Browse files
committed
redo eslint.config and prettier.config
1 parent 4eca988 commit 14bc82f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+917
-879
lines changed

eslint.config.js

Lines changed: 67 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,78 @@
11
// eslint.config.js
2-
import eslint from "@eslint/js";
3-
import tseslint from "typescript-eslint";
4-
import eslintConfigPrettier from "eslint-config-prettier";
2+
import js from "@eslint/js";
3+
import ts from "typescript-eslint";
4+
import prettierRecommended from "eslint-plugin-prettier/recommended";
55
import importPlugin from "eslint-plugin-import";
66
import unusedImports from "eslint-plugin-unused-imports";
7+
import pluginPromise from "eslint-plugin-promise";
78

8-
export default [
9+
export default ts.config(
10+
js.configs.recommended,
11+
ts.configs.recommendedTypeChecked,
12+
prettierRecommended,
13+
importPlugin.flatConfigs.recommended,
14+
pluginPromise.configs["flat/recommended"],
915
{
10-
ignores: ["**/dist/**", "**/node_modules/**", "**/coverage/**"],
11-
},
12-
...tseslint.config(
13-
eslint.configs.recommended,
14-
...tseslint.configs.recommended,
15-
eslintConfigPrettier,
16-
{
17-
files: ["src/**/*.{js,ts}", "tests/**/*.{js,ts}", "bin/**/*.{js,ts}"],
18-
plugins: {
19-
import: importPlugin,
20-
"unused-imports": unusedImports,
16+
languageOptions: {
17+
ecmaVersion: 2022,
18+
sourceType: "module",
19+
parserOptions: {
20+
project: ["./tsconfig.eslint.json"],
21+
tsconfigRootDir: import.meta.dirname,
2122
},
22-
languageOptions: {
23-
ecmaVersion: 2022,
24-
sourceType: "module",
25-
parser: tseslint.parser,
26-
},
27-
rules: {
28-
// Basic TypeScript rules
29-
"@typescript-eslint/no-unused-vars": [
30-
"warn",
31-
{
32-
ignoreRestSiblings: true,
33-
argsIgnorePattern: "^_",
34-
varsIgnorePattern: "^_",
35-
caughtErrorsIgnorePattern: "^_",
36-
},
37-
],
38-
"unused-imports/no-unused-imports": "error",
39-
"@typescript-eslint/no-explicit-any": "off",
40-
"@typescript-eslint/explicit-function-return-type": "off",
41-
"@typescript-eslint/no-floating-promises": "off",
42-
43-
// Basic code quality rules
44-
"no-console": "off",
45-
"prefer-const": "warn",
46-
"no-var": "warn",
47-
eqeqeq: ["warn", "always"],
23+
},
24+
plugins: {
25+
"unused-imports": unusedImports,
26+
},
27+
files: ["{src,test}/**/*.{js,ts}"],
28+
rules: {
29+
// Basic code quality rules
30+
"no-console": "off",
31+
"prefer-const": "warn",
32+
"no-var": "warn",
33+
eqeqeq: ["warn", "always"],
4834

49-
// Light complexity rules
50-
complexity: ["warn", { max: 20 }],
51-
"max-depth": ["warn", { max: 4 }],
52-
"max-lines-per-function": ["warn", { max: 150 }],
35+
// Light complexity rules
36+
complexity: ["warn", { max: 20 }],
37+
"max-depth": ["warn", { max: 4 }],
38+
"max-lines-per-function": ["warn", { max: 150 }],
5339

54-
// Error prevention
55-
"import/no-duplicates": "error",
56-
"no-template-curly-in-string": "warn",
40+
"@typescript-eslint/no-unsafe-assignment": "off",
41+
"@typescript-eslint/no-explicit-any": "off",
42+
"@typescript-eslint/no-unsafe-member-access": "off",
43+
"@typescript-eslint/no-unsafe-call": "off",
44+
"@typescript-eslint/no-unsafe-return": "off",
45+
"@typescript-eslint/no-unsafe-argument": "off",
46+
"@typescript-eslint/no-explicit-any": "off",
47+
"@typescript-eslint/no-unused-vars": [
48+
"error",
49+
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
50+
],
5751

58-
// Format and whitespace
59-
"max-len": [
60-
"warn",
61-
{
62-
code: 120,
63-
ignoreComments: true,
64-
ignoreStrings: true,
65-
ignoreTemplateLiterals: true,
66-
},
67-
],
52+
"import/no-unresolved": "off",
53+
"import/named": "off",
54+
"import/extensions": [
55+
"error",
56+
"ignorePackages",
57+
{ js: "always", ts: "never" },
58+
],
6859

69-
// Import rules
70-
"import/extensions": ["off"],
71-
"import/no-unresolved": "off",
60+
"no-unused-vars": "off", // or "@typescript-eslint/no-unused-vars": "off",
61+
"unused-imports/no-unused-imports": "error",
7262

73-
// Disable specific TypeScript rules that require type information
74-
"@typescript-eslint/no-unsafe-assignment": "off",
75-
"@typescript-eslint/no-unsafe-member-access": "off",
76-
"@typescript-eslint/no-unsafe-call": "off",
77-
"@typescript-eslint/no-unsafe-return": "off",
78-
},
79-
}
80-
),
81-
];
63+
"promise/always-return": "error",
64+
"promise/no-return-wrap": "error",
65+
"promise/param-names": "error",
66+
"promise/catch-or-return": "error",
67+
"promise/no-native": "off",
68+
"promise/no-nesting": "warn",
69+
"promise/no-promise-in-callback": "warn",
70+
"promise/no-callback-in-promise": "warn",
71+
"promise/avoid-new": "off",
72+
"promise/no-new-statics": "error",
73+
"promise/no-return-in-finally": "warn",
74+
"promise/valid-params": "warn",
75+
"promise/no-multiple-resolved": "error",
76+
},
77+
}
78+
);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"build:ci": "tsc",
2525
"clean": "rimraf dist",
2626
"clean:all": "rimraf dist node_modules",
27-
"lint": "eslint . --fix",
27+
"lint": "eslint \"{src,test}/**/*.{js,ts}\" --fix",
2828
"format": "prettier --write \"src/**/*.*\"",
2929
"test": "vitest run",
3030
"test:watch": "vitest",
@@ -52,6 +52,7 @@
5252
"@anthropic-ai/sdk": "^0.36",
5353
"chalk": "^5",
5454
"dotenv": "^16",
55+
"eslint-plugin-promise": "^7.2.1",
5556
"semver": "^7.7.1",
5657
"source-map-support": "^0.5",
5758
"uuid": "^11",

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prettier.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// prettier.config.ts, .prettierrc.ts, prettier.config.mts, or .prettierrc.mts
2+
3+
import { type Config } from "prettier";
4+
5+
const config: Config = {
6+
trailingComma: "all",
7+
tabWidth: 2,
8+
semi: true,
9+
singleQuote: true,
10+
};
11+
12+
export default config;

src/commands/$default.ts

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
1-
import * as fs from "fs/promises";
2-
import { createInterface } from "readline/promises";
3-
import { ArgumentsCamelCase } from "yargs";
4-
import { toolAgent } from "../core/toolAgent.js";
5-
import { SharedOptions } from "../options.js";
6-
import { createRequire } from "module";
7-
import { Logger } from "../utils/logger.js";
8-
import { getTools } from "../tools/getTools.js";
1+
import * as fs from 'fs/promises';
2+
import { createInterface } from 'readline/promises';
3+
import { ArgumentsCamelCase, Argv } from 'yargs';
4+
import { toolAgent } from '../core/toolAgent.js';
5+
import { SharedOptions } from '../options.js';
6+
import { Logger } from '../utils/logger.js';
7+
import { getTools } from '../tools/getTools.js';
98

10-
import { getAnthropicApiKeyError } from "../utils/errors.js";
9+
import { getAnthropicApiKeyError } from '../utils/errors.js';
10+
import { getPackageInfo } from '../utils/versionCheck.js';
1111

1212
interface Options extends SharedOptions {
1313
prompt?: string;
1414
}
1515

16-
export const command = "* [prompt]";
17-
export const describe = "Execute a prompt or start interactive mode";
16+
export const command = '* [prompt]';
17+
export const describe = 'Execute a prompt or start interactive mode';
1818

19-
export const builder = (yargs) => {
20-
return yargs.positional("prompt", {
21-
type: "string",
22-
description: "The prompt to execute",
19+
export const builder = (yargs: Argv<Options>) => {
20+
return yargs.positional('prompt', {
21+
type: 'string',
22+
description: 'The prompt to execute',
2323
}); // Type assertion needed due to yargs typing complexity
2424
};
2525

2626
export const handler = async (argv: ArgumentsCamelCase<Options>) => {
27-
const logger = new Logger({ name: "Default" });
28-
const require = createRequire(import.meta.url);
29-
const packageInfo = require("../../package.json");
27+
const logger = new Logger({ name: 'Default' });
28+
const packageInfo = getPackageInfo();
3029

3130
logger.info(`MyCoder v${packageInfo.version} - AI-powered coding assistant`);
3231
logger.warn(
33-
"WARNING: This tool can do anything on your command line that you ask it to.",
34-
"It can delete files, install software, and even send data to remote servers.",
35-
"It is a powerful tool that should be used with caution.",
36-
"By using this tool, you agree that the authors and contributors are not responsible for any damage that may occur as a result of using this tool.",
32+
'WARNING: This tool can do anything on your command line that you ask it to.',
33+
'It can delete files, install software, and even send data to remote servers.',
34+
'It is a powerful tool that should be used with caution.',
35+
'By using this tool, you agree that the authors and contributors are not responsible for any damage that may occur as a result of using this tool.',
3736
);
3837
try {
3938
// Early API key check
@@ -47,7 +46,7 @@ export const handler = async (argv: ArgumentsCamelCase<Options>) => {
4746
// If promptFile is specified, read from file
4847
if (argv.file) {
4948
try {
50-
prompt = await fs.readFile(argv.file, "utf-8");
49+
prompt = await fs.readFile(argv.file, 'utf-8');
5150
} catch (error: any) {
5251
logger.error(
5352
`Failed to read prompt file: ${argv.file}, ${error?.message}`,
@@ -67,7 +66,7 @@ export const handler = async (argv: ArgumentsCamelCase<Options>) => {
6766
logger.info(
6867
"Type your request below or 'help' for usage information. Use Ctrl+C to exit.",
6968
);
70-
prompt = await readline.question("\n> ");
69+
prompt = await readline.question('\n> ');
7170
} finally {
7271
readline.close();
7372
}
@@ -78,27 +77,27 @@ export const handler = async (argv: ArgumentsCamelCase<Options>) => {
7877

7978
if (!prompt) {
8079
logger.error(
81-
"No prompt provided. Either specify a prompt, use --promptFile, or run in --interactive mode.",
80+
'No prompt provided. Either specify a prompt, use --promptFile, or run in --interactive mode.',
8281
);
8382
process.exit(1);
8483
}
8584

8685
// Add the standard suffix to all prompts
8786
prompt += [
88-
"Please ask for clarifications if required or if the tasks is confusing.",
87+
'Please ask for clarifications if required or if the tasks is confusing.',
8988
"If you need more context, don't be scared to create a sub-agent to investigate and generate report back, this can save a lot of time and prevent obvious mistakes.",
90-
"Once the task is complete ask the user, via the userPrompt tool if the results are acceptable or if changes are needed or if there are additional follow on tasks.",
91-
].join("\n");
89+
'Once the task is complete ask the user, via the userPrompt tool if the results are acceptable or if changes are needed or if there are additional follow on tasks.',
90+
].join('\n');
9291

93-
const tools = await getTools();
92+
const tools = getTools();
9493
const result = await toolAgent(prompt, tools, logger);
9594
const output =
96-
typeof result.result === "string"
95+
typeof result.result === 'string'
9796
? result.result
9897
: JSON.stringify(result.result, null, 2);
99-
logger.info("\n=== Result ===\n", output);
98+
logger.info('\n=== Result ===\n', output);
10099
} catch (error) {
101-
logger.error("An error occurred:", error);
100+
logger.error('An error occurred:', error);
102101
process.exit(1);
103102
}
104103
};

0 commit comments

Comments
 (0)