Skip to content

Commit 0659d4c

Browse files
authored
More project DX ergonomics (#20)
* wip dx changes * adding development conditions and distinct build tsconfig * consistent eslint and prettier config; run fix across code * remove testing function call * linting for build
1 parent 1a5f8d6 commit 0659d4c

33 files changed

Lines changed: 617 additions & 867 deletions

eslint.config.mjs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2025, Salesforce, Inc.
3+
* SPDX-License-Identifier: Apache-2
4+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
7+
/**
8+
* Shared ESLint configuration for the b2c-cli monorepo.
9+
* Packages import from this file to maintain consistency.
10+
*/
11+
12+
import prettierPlugin from 'eslint-plugin-prettier/recommended';
13+
14+
/**
15+
* The standard copyright header block used across all packages.
16+
*/
17+
export const copyrightHeader = [
18+
'',
19+
' * Copyright (c) 2025, Salesforce, Inc.',
20+
' * SPDX-License-Identifier: Apache-2',
21+
' * For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0',
22+
' ',
23+
];
24+
25+
/**
26+
* Shared rules used across all packages.
27+
*/
28+
export const sharedRules = {
29+
// Allow underscore-prefixed unused variables (common convention for intentionally unused params)
30+
'@typescript-eslint/no-unused-vars': [
31+
'error',
32+
{
33+
argsIgnorePattern: '^_',
34+
varsIgnorePattern: '^_',
35+
},
36+
],
37+
// Disable new-cap - incompatible with openapi-fetch (uses GET, POST, etc. methods)
38+
'new-cap': 'off',
39+
};
40+
41+
/**
42+
* Rules for packages using eslint-config-oclif.
43+
* Disables perfectionist and stylistic rules that conflict with our style.
44+
*/
45+
export const oclifRules = {
46+
// Disable perfectionist rules - we use prettier for formatting
47+
'perfectionist/sort-imports': 'off',
48+
'perfectionist/sort-objects': 'off',
49+
'perfectionist/sort-object-types': 'off',
50+
'perfectionist/sort-interfaces': 'off',
51+
'perfectionist/sort-named-exports': 'off',
52+
'perfectionist/sort-named-imports': 'off',
53+
// Disable stylistic rules that conflict with our style
54+
'@stylistic/lines-between-class-members': 'off',
55+
'@stylistic/padding-line-between-statements': 'off',
56+
// Allow TODO comments
57+
'no-warning-comments': 'off',
58+
// Don't require destructuring
59+
'prefer-destructuring': 'off',
60+
};
61+
62+
/**
63+
* Rules for test files using Chai assertions.
64+
*/
65+
export const chaiTestRules = {
66+
// Allow Chai property-based assertions in test files (e.g., expect(x).to.be.true)
67+
'@typescript-eslint/no-unused-expressions': 'off',
68+
};
69+
70+
/**
71+
* Re-export prettier plugin for convenience.
72+
*/
73+
export {prettierPlugin};

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"license": "Apache-2.0",
2222
"packageManager": "pnpm@10.17.1",
2323
"devDependencies": {
24+
"eslint-plugin-prettier": "^5.5.4",
25+
"prettier": "^3.6.2",
2426
"typedoc": "^0.28.14",
2527
"typedoc-plugin-markdown": "^4.9.0",
2628
"typedoc-vitepress-theme": "^1.1.2",

packages/b2c-cli/bin/dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env -S node --conditions development --import tsx
1+
#!/usr/bin/env -S node --conditions development
22
/*
33
* Copyright (c) 2025, Salesforce, Inc.
44
* SPDX-License-Identifier: Apache-2

packages/b2c-cli/eslint.config.mjs

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
*/
66
import {includeIgnoreFile} from '@eslint/compat';
77
import oclif from 'eslint-config-oclif';
8-
import prettierPlugin from 'eslint-plugin-prettier/recommended';
9-
import headerPlugin from '@tony.ganchev/eslint-plugin-header';
8+
import headerPlugin from 'eslint-plugin-header';
109
import path from 'node:path';
1110
import {fileURLToPath} from 'node:url';
1211

12+
import {copyrightHeader, sharedRules, oclifRules, prettierPlugin} from '../../eslint.config.mjs';
13+
1314
const gitignorePath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '.gitignore');
15+
headerPlugin.rules.header.meta.schema = false;
1416

1517
export default [
1618
includeIgnoreFile(gitignorePath),
@@ -24,41 +26,9 @@ export default [
2426
header: headerPlugin,
2527
},
2628
rules: {
27-
'header/header': [
28-
'error',
29-
'block',
30-
[
31-
'',
32-
' * Copyright (c) 2025, Salesforce, Inc.',
33-
' * SPDX-License-Identifier: Apache-2',
34-
' * For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0',
35-
' ',
36-
],
37-
],
38-
// Disable perfectionist rules - we use prettier for formatting
39-
'perfectionist/sort-imports': 'off',
40-
'perfectionist/sort-objects': 'off',
41-
'perfectionist/sort-object-types': 'off',
42-
'perfectionist/sort-interfaces': 'off',
43-
'perfectionist/sort-named-exports': 'off',
44-
'perfectionist/sort-named-imports': 'off',
45-
// Disable stylistic rules that conflict with our style
46-
'@stylistic/lines-between-class-members': 'off',
47-
'@stylistic/padding-line-between-statements': 'off',
48-
// Allow TODO comments
49-
'no-warning-comments': 'off',
50-
// Don't require destructuring
51-
'prefer-destructuring': 'off',
52-
// Disable new-cap - incompatible with openapi-fetch (uses GET, POST, etc. methods)
53-
'new-cap': 'off',
54-
// Allow underscore-prefixed unused variables
55-
'@typescript-eslint/no-unused-vars': [
56-
'error',
57-
{
58-
argsIgnorePattern: '^_',
59-
varsIgnorePattern: '^_',
60-
},
61-
],
29+
'header/header': ['error', 'block', copyrightHeader],
30+
...sharedRules,
31+
...oclifRules,
6232
},
6333
},
6434
];

packages/b2c-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@oclif/prettier-config": "^0.2.1",
2323
"@oclif/test": "^4",
2424
"@salesforce/dev-config": "^4.3.2",
25-
"@tony.ganchev/eslint-plugin-header": "^3.1.11",
25+
"eslint-plugin-header": "^3.1.1",
2626
"@types/chai": "^4",
2727
"@types/mocha": "^10",
2828
"@types/node": "^18",

packages/b2c-cli/src/commands/_test/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default class Test extends BaseCommand<typeof Test> {
1111

1212
async run(): Promise<void> {
1313
// Test this.log() which now uses pino
14+
this.baseCommandTest();
1415
this.log('Using this.log() - goes through pino');
1516
this.warn('Using this.warn() - goes through pino');
1617

packages/b2c-dx-mcp/.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
*-debug.log
2+
*-error.log
3+
**/.DS_Store
4+
/.idea
5+
/dist
6+
/build
7+
/tmp
8+
/node_modules
9+
/coverage
10+
test-results.json
11+
oclif.manifest.json
12+
13+
14+
yarn.lock
15+
package-lock.json
16+
17+
dw.json
18+
19+
export/

packages/b2c-dx-mcp/bin/dev.js

100644100755
Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
1-
#!/usr/bin/env -S node --conditions development --import tsx
1+
#!/usr/bin/env -S node --conditions development
22
/*
33
* Copyright (c) 2025, Salesforce, Inc.
44
* SPDX-License-Identifier: Apache-2
55
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
66
*/
7-
/* global process */
8-
9-
/**
10-
* Development entry point for MCP server using oclif.
11-
*
12-
* This uses oclif's development mode which:
13-
* - Uses TypeScript source directly (via tsx loader in shebang)
14-
* - Supports the 'development' condition for exports
15-
* - Loads .env file if present for local configuration
16-
* - Provides better error messages and stack traces
17-
*
18-
* Run directly: ./bin/dev.js mcp --toolsets all
19-
* Or with node: node --conditions development --import tsx bin/dev.js mcp --toolsets all
20-
*/
217

228
// Load .env file if present (Node.js native support)
239
try {
Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,31 @@
11
/*
2-
* Copyright 2025, Salesforce, Inc.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright (c) 2025, Salesforce, Inc.
3+
* SPDX-License-Identifier: Apache-2
4+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
155
*/
6+
import {includeIgnoreFile} from '@eslint/compat';
7+
import oclif from 'eslint-config-oclif';
8+
import headerPlugin from 'eslint-plugin-header';
9+
import path from 'node:path';
10+
import {fileURLToPath} from 'node:url';
1611

17-
import eslint from '@eslint/js';
18-
import tseslint from 'typescript-eslint';
19-
import prettierConfig from 'eslint-config-prettier';
12+
import {copyrightHeader, sharedRules, oclifRules, prettierPlugin} from '../../eslint.config.mjs';
2013

21-
export default tseslint.config(
22-
eslint.configs.recommended,
23-
...tseslint.configs.recommended,
24-
prettierConfig,
25-
{
26-
ignores: ['dist/**', 'node_modules/**'],
27-
},
14+
const gitignorePath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '.gitignore');
15+
headerPlugin.rules.header.meta.schema = false;
16+
17+
export default [
18+
includeIgnoreFile(gitignorePath),
19+
...oclif,
20+
prettierPlugin,
2821
{
29-
rules: {
30-
'@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_'}],
31-
'@typescript-eslint/no-explicit-any': 'warn',
22+
plugins: {
23+
header: headerPlugin,
3224
},
33-
},
34-
// Allow chai assertion expressions in test files
35-
{
36-
files: ['test/**/*.ts'],
3725
rules: {
38-
'@typescript-eslint/no-unused-expressions': 'off',
26+
'header/header': ['error', 'block', copyrightHeader],
27+
...sharedRules,
28+
...oclifRules,
3929
},
4030
},
41-
);
42-
31+
];

0 commit comments

Comments
 (0)