Skip to content

Commit e6fbbee

Browse files
committed
Merge branch 'main' into typescript
2 parents 3850162 + d044441 commit e6fbbee

26 files changed

+1920
-1035
lines changed

eslint.config.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import jsdoc from "eslint-plugin-jsdoc";
22
import {configs as tseslintConfigs} from 'typescript-eslint';
3+
import eslintjs from "@eslint/js";
4+
5+
const {configs: eslintConfigs} = eslintjs;
36

47
export default [
5-
...tseslintConfigs.recommended,
68
jsdoc.configs["flat/recommended"],
9+
eslintConfigs["recommended"],
10+
...tseslintConfigs.recommended,
711
{
12+
languageOptions: {
13+
// if we ever use more globals than this, pull in the `globals` package
14+
globals: {
15+
console: false
16+
}
17+
},
818
rules: {
919
"jsdoc/require-param-description": "off",
1020
"jsdoc/require-returns-description": "off",
@@ -16,8 +26,9 @@ export default [
1626
"prefer-rest-params": "off",
1727
"@typescript-eslint/no-unused-expressions": "off",
1828
"@typescript-eslint/no-unused-vars": ["error", {
29+
"argsIgnorePattern": "^_",
1930
"caughtErrorsIgnorePattern": "^_"
20-
}]
31+
}],
2132
},
2233
},
2334
];

package-lock.json

+15-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
"prebuild": "npm run clean",
3737
"build": "npm run build:esm",
3838
"build:esm": "esbuild --bundle --format=esm --keep-names --outfile=chai.js src/chai.ts",
39-
"format": "prettier --write lib",
39+
"format": "prettier --write src",
4040
"pretest": "npm run lint && npm run build",
4141
"test": "npm run test-node && npm run test-chrome",
4242
"test-node": "mocha --require ./test/bootstrap/index.js --reporter dot test/*.js",
4343
"test-chrome": "web-test-runner --playwright",
4444
"lint": "npm run lint:js && npm run lint:format && npm run lint:types",
4545
"lint:js": "eslint src",
46-
"lint:format": "prettier --check lib",
46+
"lint:format": "prettier --check src",
4747
"lint:types": "tsc --noEmit",
4848
"clean": "rm -rf chai.js coverage lib"
4949
},
@@ -61,6 +61,7 @@
6161
"pathval": "^2.0.0"
6262
},
6363
"devDependencies": {
64+
"@eslint/js": "^9.17.0",
6465
"@rollup/plugin-commonjs": "^25.0.7",
6566
"@web/dev-server-rollup": "^0.6.1",
6667
"@web/test-runner": "^0.18.0",

src/chai/assertion.ts

+49-33
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ type MethodNames<T> = {
2727
}[keyof T];
2828

2929
const getDefaultValue = <T>(assertion: Assertion<T>): Assertion<T> => {
30-
var newAssertion = Assertion.create<T>();
31-
util.transferFlags(assertion, newAssertion);
32-
return newAssertion;
30+
var newAssertion = Assertion.create<T>();
31+
util.transferFlags(assertion, newAssertion);
32+
return newAssertion;
3333
};
3434

3535
/*!
@@ -71,7 +71,10 @@ const getDefaultValue = <T>(assertion: Assertion<T>): Assertion<T> => {
7171
* @param {boolean} lockSsfi (optional) whether or not the ssfi flag is locked
7272
* @private
7373
*/
74-
export class Assertion<T, TFlags extends AssertionFlags<T> = AssertionFlags<T>> {
74+
export class Assertion<
75+
T,
76+
TFlags extends AssertionFlags<T> = AssertionFlags<T>
77+
> {
7578
declare public __flags: TFlags;
7679
public __methods: Record<string, ChainableBehavior> = {};
7780

@@ -94,50 +97,52 @@ export class Assertion<T, TFlags extends AssertionFlags<T> = AssertionFlags<T>>
9497
ssfi?: Function,
9598
lockSsfi?: boolean
9699
): Assertion<TObj> {
97-
return util.proxify(new Assertion<TObj>(
98-
obj,
99-
msg,
100-
ssfi,
101-
lockSsfi
102-
));
100+
return util.proxify(new Assertion<TObj>(obj, msg, ssfi, lockSsfi));
103101
}
104102

105103
public static get includeStack(): boolean {
106-
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
104+
console.warn(
105+
'Assertion.includeStack is deprecated, use chai.config.includeStack instead.'
106+
);
107107
return config.includeStack;
108108
}
109109

110110
public static set includeStack(value: boolean) {
111-
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
111+
console.warn(
112+
'Assertion.includeStack is deprecated, use chai.config.includeStack instead.'
113+
);
112114
config.includeStack = value;
113115
}
114116

115117
public static get showDiff(): boolean {
116-
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
118+
console.warn(
119+
'Assertion.showDiff is deprecated, use chai.config.showDiff instead.'
120+
);
117121
return config.showDiff;
118122
}
119123

120124
public static set showDiff(value: boolean) {
121-
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
125+
console.warn(
126+
'Assertion.showDiff is deprecated, use chai.config.showDiff instead.'
127+
);
122128
config.showDiff = value;
123129
}
124130

125-
public static addProperty(name: string, fn?: (this: Assertion<unknown>) => unknown): void {
131+
public static addProperty(
132+
name: string,
133+
fn?: (this: Assertion<unknown>) => unknown
134+
): void {
126135
util.addProperty(this.prototype, name, fn, getDefaultValue);
127136
}
128137

129-
public static addMethod<
130-
TKey extends PropertyKey
131-
>(
138+
public static addMethod<TKey extends PropertyKey>(
132139
name: TKey,
133-
fn: TKey extends MethodNames<Assertion<unknown>> ?
134-
(
135-
this: Assertion<unknown>,
136-
...args: Parameters<Assertion<unknown>[TKey]>
137-
) => (
138-
ReturnType<Assertion<unknown>[TKey]> | void
139-
) :
140-
((this: Assertion<unknown>, ...args: never) => unknown)
140+
fn: TKey extends MethodNames<Assertion<unknown>>
141+
? (
142+
this: Assertion<unknown>,
143+
...args: Parameters<Assertion<unknown>[TKey]>
144+
) => ReturnType<Assertion<unknown>[TKey]> | void
145+
: (this: Assertion<unknown>, ...args: never) => unknown
141146
): void {
142147
util.addMethod(this.prototype, name, fn, getDefaultValue);
143148
}
@@ -164,8 +169,18 @@ export class Assertion<T, TFlags extends AssertionFlags<T> = AssertionFlags<T>>
164169
util.overwriteMethod(this.prototype, name, fn, getDefaultValue);
165170
}
166171

167-
public static overwriteChainableMethod(name: string, fn: Function, chainingBehavior: Function): void {
168-
util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior, getDefaultValue);
172+
public static overwriteChainableMethod(
173+
name: string,
174+
fn: Function,
175+
chainingBehavior: Function
176+
): void {
177+
util.overwriteChainableMethod(
178+
this.prototype,
179+
name,
180+
fn,
181+
chainingBehavior,
182+
getDefaultValue
183+
);
169184
}
170185

171186
/**
@@ -199,10 +214,10 @@ export class Assertion<T, TFlags extends AssertionFlags<T> = AssertionFlags<T>>
199214
msg = util.getMessage(this, arguments);
200215
var actual = util.getActual(this, arguments);
201216
var assertionErrorObjectProperties: Record<string, unknown> = {
202-
actual: actual
203-
, expected: expected
204-
, showDiff: showDiff
205-
, operator: undefined
217+
actual: actual,
218+
expected: expected,
219+
showDiff: showDiff,
220+
operator: undefined
206221
};
207222

208223
var operator = util.getOperator(this, arguments);
@@ -213,7 +228,8 @@ export class Assertion<T, TFlags extends AssertionFlags<T> = AssertionFlags<T>>
213228
throw new AssertionError(
214229
msg,
215230
assertionErrorObjectProperties,
216-
(config.includeStack) ? this.assert : util.flag(this, 'ssfi'));
231+
config.includeStack ? this.assert : util.flag(this, 'ssfi')
232+
);
217233
}
218234
}
219235

0 commit comments

Comments
 (0)