Skip to content

Latest commit

Β 

History

History
60 lines (47 loc) Β· 1.6 KB

File metadata and controls

60 lines (47 loc) Β· 1.6 KB

no-invalid-well-known-symbol-methods

πŸ“ Disallow invalid implementations of well-known symbol methods.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ”§πŸ’‘ This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

Some well-known symbol methods must return protocol objects directly. Marking those methods as async or returning a Promise changes the value seen by the protocol, which does not unwrap it.

Symbol.dispose is also synchronous. A Promise returned from it is ignored by using and is not awaited. A generator disposer is also invalid because calling it does not run the body. Use a normal method for synchronous disposal or Symbol.asyncDispose for asynchronous disposal.

Examples

// ❌
class Resource {
	async [Symbol.dispose]() {}
}

// βœ…
class Resource {
	async [Symbol.asyncDispose]() {}
}
// ❌
const iterable = {
	async *[Symbol.iterator]() {
		yield value;
	},
};

// βœ…
const iterable = {
	async *[Symbol.asyncIterator]() {
		yield value;
	},
};
// ❌
const asyncIterable = {
	async [Symbol.asyncIterator]() {
		return iterator;
	},
};

// βœ…
const asyncIterable = {
	async *[Symbol.asyncIterator]() {
		yield value;
	},
};