Skip to content

Commit

Permalink
chore: enable no-explicit-any rule as error level
Browse files Browse the repository at this point in the history
Removes our override such that `any` is no longer allowed, and replaces
usages of it.
  • Loading branch information
43081j committed Jan 6, 2025
1 parent eed590e commit 5c5f63e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 33 deletions.
1 change: 0 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default [
rules: {
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/consistent-type-imports': 'error',

Expand Down
2 changes: 1 addition & 1 deletion packages/parse5-html-rewriting-stream/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,5 @@ export interface RewritingStream {
* @param event Name of the event
* @param handler Event handler
*/
on(event: string, handler: (...args: any[]) => void): this;
on(event: string, handler: (...args: never[]) => void): this;
}
2 changes: 1 addition & 1 deletion packages/parse5-parser-stream/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,5 @@ export interface ParserStream<T extends TreeAdapterTypeMap = DefaultTreeAdapterM
* @param event Name of the event
* @param handler Event handler
*/
on(event: string, handler: (...args: any[]) => void): this;
on(event: string, handler: (...args: never[]) => void): this;
}
2 changes: 1 addition & 1 deletion packages/parse5-sax-parser/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,5 @@ export interface SAXParser {
* @param event Name of the event
* @param handler Event handler
*/
on(event: string, handler: (...args: any[]) => void): this;
on(event: string, handler: (...args: never[]) => void): this;
}
75 changes: 48 additions & 27 deletions packages/parse5/lib/parser/parser-location-info.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import * as assert from 'node:assert';
import { outdent } from 'outdent';
import { type ParserOptions, type TreeAdapterTypeMap, parse, parseFragment } from 'parse5';
import {
type ParserOptions,
type TreeAdapterTypeMap,
parse,
parseFragment,
type DefaultTreeAdapterMap,
type Token,
} from 'parse5';
import {
generateLocationInfoParserTests,
assertStartTagLocation,
Expand Down Expand Up @@ -230,32 +237,34 @@ generateTestsForEachTreeAdapter('location-info-parser', (treeAdapter) => {
describe('location-info-parser', () => {
it('Updating node source code location (GH-314)', () => {
const sourceCodeLocationSetter = {
setNodeSourceCodeLocation(node: any, location: any): void {
setNodeSourceCodeLocation(
node: DefaultTreeAdapterMap['node'],
location: Token.ElementLocation | null,
): void {
node.sourceCodeLocation =
location === null
? null
: {
start: {
line: location.startLine,
column: location.startCol,
offset: location.startOffset,
},
end: {
line: location.endLine,
column: location.endCol,
offset: location.endOffset,
},
startLine: location.startLine * 2,
startCol: location.startCol * 2,
startOffset: location.startOffset * 2,
endLine: location.endLine * 2,
endCol: location.endCol * 2,
endOffset: location.endOffset * 2,
};
},
updateNodeSourceCodeLocation(node: any, endLocation: any): void {
node.sourceCodeLocation = {
start: node.sourceCodeLocation.start,
end: {
line: endLocation.endLine,
column: endLocation.endCol,
offset: endLocation.endOffset,
},
};
updateNodeSourceCodeLocation(
node: DefaultTreeAdapterMap['node'],
endLocation: Token.ElementLocation,
): void {
if (node.sourceCodeLocation) {
node.sourceCodeLocation = {
...node.sourceCodeLocation,
endLine: endLocation.endLine * 2,
endCol: endLocation.endCol * 2,
endOffset: endLocation.endOffset * 2,
};
}
},
};
const treeAdapter = { ...treeAdapters.default, ...sourceCodeLocationSetter };
Expand All @@ -270,18 +279,30 @@ describe('location-info-parser', () => {
const [text] = body.childNodes;

assert.deepEqual(doctype.sourceCodeLocation, {
start: { line: 1, column: 1, offset: 0 },
end: { line: 1, column: 11, offset: 10 },
startLine: 2,
startCol: 2,
startOffset: 0,
endLine: 2,
endCol: 22,
endOffset: 20,
});
assert.strictEqual(html.sourceCodeLocation, null);
assert.strictEqual(head.sourceCodeLocation, null);
assert.deepEqual(body.sourceCodeLocation, {
start: { line: 1, column: 11, offset: 10 },
end: { line: 1, column: 40, offset: 39 },
startLine: 2,
startCol: 22,
startOffset: 20,
endLine: 2,
endCol: 80,
endOffset: 78,
});
assert.deepEqual(text.sourceCodeLocation, {
start: { line: 1, column: 17, offset: 16 },
end: { line: 1, column: 33, offset: 32 },
startLine: 2,
startCol: 34,
startOffset: 32,
endLine: 2,
endCol: 66,
endOffset: 64,
});
});
});
2 changes: 1 addition & 1 deletion packages/parse5/lib/serializer/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('serializer', () => {
});

it('serializes unknown node to empty string', () => {
const unknown: any = {};
const unknown = {} as never;
assert.strictEqual(serialize(unknown), '');
assert.strictEqual(serializeOuter(unknown), '');
});
Expand Down
2 changes: 1 addition & 1 deletion packages/parse5/lib/tokenizer/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Tokenizer methods', () => {
});

it('should throw if setting the state to an unknown value', () => {
const tokenizer = new Tokenizer(tokenizerOpts, {} as any);
const tokenizer = new Tokenizer(tokenizerOpts, {} as never);
tokenizer.state = -1 as never;
expect(() => tokenizer.write('foo', true)).toThrow('Unknown state');
});
Expand Down

0 comments on commit 5c5f63e

Please sign in to comment.