Skip to content

Commit 61d4d33

Browse files
committed
Adopts new ESLint flat configuration
Migrates the project's ESLint setup from the deprecated .eslintrc.json format to the new eslint.config.js flat configuration. This change enhances maintainability and provides more granular control over linting rules. The update includes new dev dependencies for ESLint and defines specific rules and globals tailored for .mjs files in the bin and tests directories. Additionally, performs minor code cleanups by removing unused variables and functions, refining imports, and correcting a missing brace in the `init` command.
1 parent 624c4ac commit 61d4d33

10 files changed

Lines changed: 68 additions & 37 deletions

File tree

‎.eslintrc.json‎

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎bin/commands/doctor.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export async function doctor(options) {
2626
console.log(` Target: ${targetDir}\n`);
2727

2828
let allGood = true;
29-
let fixesApplied = false;
3029

3130
// 1. Check Node.js version
3231
const nodeVersion = process.version;

‎bin/commands/init.mjs‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const __filename = fileURLToPath(import.meta.url);
1515
const __dirname = dirname(__filename);
1616
const PKG_ROOT = join(__dirname, '..', '..');
1717
const TEMPLATE_DIR = join(PKG_ROOT, 'template');
18+
const PKG_NAME = 'opencode-agent-kit';
1819

1920
// ANSI colors
2021
const C = {
@@ -43,11 +44,6 @@ function error(msg) {
4344
console.log(` ${C.red}✗${C.reset} ${msg}`);
4445
}
4546

46-
function header(title) {
47-
console.log(`\n ${C.bold}${title}${C.reset}`);
48-
console.log(` ${C.dim}${'─'.repeat(50)}${C.reset}`);
49-
}
50-
5147
function copyRecursive(src, dest) {
5248
if (!existsSync(src)) return;
5349
const entries = readdirSync(src, { withFileTypes: true });
@@ -186,6 +182,7 @@ export async function init(options) {
186182
console.error(` ✗ Target directory does not exist: ${targetDir}`);
187183
error(`Target directory does not exist: ${targetDir}`);
188184
process.exit(1);
185+
}
189186

190187
// 2. Check if .opencode already exists
191188
const opencodeDir = join(targetDir, '.opencode');

‎bin/commands/uninstall.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, readFileSync, unlinkSync, rmSync, readdirSync } from 'fs';
1+
import { existsSync, readFileSync, unlinkSync, rmSync } from 'fs';
22
import { join } from 'path';
33
import { createInterface } from 'readline/promises';
44

‎bin/commands/upgrade.mjs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { execSync } from 'child_process';
2-
import { readFileSync, existsSync } from 'fs';
3-
import { join } from 'path';
4-
2+
import { readFileSync } from 'fs';
53
const PKG_NAME = 'opencode-agent-kit';
64

75
/**
86
* Get the currently installed version from package.json
97
*/
108
function getCurrentVersion() {
11-
const pkgPath = new URL('../../package.json', import.meta.url);
9+
const pkgPath = new globalThis.URL('../../package.json', import.meta.url);
1210
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
1311
return pkg.version;
1412
}

‎eslint.config.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import js from '@eslint/js';
2+
import prettier from 'eslint-config-prettier';
3+
4+
export default [
5+
js.configs.recommended,
6+
prettier,
7+
{
8+
files: ['bin/**/*.mjs', 'tests/**/*.mjs'],
9+
languageOptions: {
10+
ecmaVersion: 'latest',
11+
sourceType: 'module',
12+
globals: {
13+
console: 'readonly',
14+
process: 'readonly',
15+
setTimeout: 'readonly',
16+
clearInterval: 'readonly',
17+
setInterval: 'readonly',
18+
Buffer: 'readonly',
19+
__dirname: 'readonly',
20+
__filename: 'readonly',
21+
require: 'readonly',
22+
},
23+
},
24+
rules: {
25+
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
26+
'no-console': 'off',
27+
'prefer-const': 'error',
28+
'no-var': 'error',
29+
},
30+
},
31+
{
32+
ignores: ['node_modules/', 'template/', 'data/', 'coverage/'],
33+
},
34+
];

‎package-lock.json‎

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

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"fs-extra": "^11.0.0"
6868
},
6969
"devDependencies": {
70+
"@eslint/js": "^10.0.1",
7071
"eslint": "^9.0.0",
7172
"eslint-config-prettier": "^9.1.0",
7273
"prettier": "^3.4.0",

‎tests/config.test.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('source opencode.json (project root)', () => {
5858
it('has valid permissions for all agents', () => {
5959
const config = JSON.parse(readFileSync(configPath, 'utf-8'));
6060
const validValues = ['allow', 'deny', 'ask'];
61-
for (const [name, agent] of Object.entries(config.agent)) {
61+
for (const [, agent] of Object.entries(config.agent)) {
6262
if (agent.permission?.edit) {
6363
expect(validValues).toContain(agent.permission.edit);
6464
}

‎tests/package.test.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('package structure', () => {
2828
'bin/commands/uninstall.mjs',
2929
'.editorconfig',
3030
'.prettierrc',
31-
'.eslintrc.json',
31+
'eslint.config.js',
3232
'.gitignore',
3333
'schema/opencode-config.schema.json',
3434
];

0 commit comments

Comments
 (0)