Skip to content

Commit de58244

Browse files
committed
chore: use isolated declarations
1 parent 3e472e9 commit de58244

6 files changed

Lines changed: 19 additions & 14 deletions

File tree

eslint.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ export default [
2626
files: ["**/*.js"],
2727
...tseslint.configs.disableTypeChecked,
2828
},
29+
{
30+
rules: {
31+
"@typescript-eslint/no-inferrable-types": "off",
32+
},
33+
},
2934
];

src/constants.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { CSS_SELECTOR_TYPE } from "./types.js";
1+
import { CSS_SELECTOR_TYPE, CssSelectorType } from "./types.js";
22

33
export const SELECTOR_SEPARATOR = ", ";
44

55
// RegExp that will match invalid patterns that can be used in ID attribute.
6-
export const INVALID_ID_RE = new RegExp(
6+
export const INVALID_ID_RE: RegExp = new RegExp(
77
[
88
"^$", // empty or not set
99
"\\s", // contains whitespace
1010
].join("|"),
1111
);
1212

1313
// RegExp that will match invalid patterns that can be used in class attribute.
14-
export const INVALID_CLASS_RE = new RegExp(
14+
export const INVALID_CLASS_RE: RegExp = new RegExp(
1515
[
1616
"^$", // empty or not set
1717
].join("|"),
1818
);
1919

2020
// Order in which a combined selector is constructed.
21-
export const SELECTOR_PATTERN = [
21+
export const SELECTOR_PATTERN: CssSelectorType[] = [
2222
CSS_SELECTOR_TYPE.nthoftype,
2323
CSS_SELECTOR_TYPE.tag,
2424
CSS_SELECTOR_TYPE.id,

src/selector-attribute.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { sanitizeSelectorItem } from "./utilities-selectors.js";
22
import { createPatternMatcher, getIntersection } from "./utilities-data.js";
3-
import { CssSelectorGenerated } from "./types.js";
3+
import { CssSelectorGenerated, PatternMatcher } from "./types.js";
44

55
interface AttributeData {
66
name: string;
77
value: string;
88
}
99

1010
// List of attributes to be ignored. These are handled by different selector types.
11-
export const attributeBlacklistMatch = createPatternMatcher([
11+
export const attributeBlacklistMatch: PatternMatcher = createPatternMatcher([
1212
"class",
1313
"id",
1414
// Angular attributes

src/utilities-selectors.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ import { isElement } from "./utilities-iselement.js";
3535
import { getPowerSet, powerSetGenerator } from "./utilities-powerset.js";
3636
import { cartesianProductGenerator } from "./utilities-cartesian.js";
3737

38-
export const ESCAPED_COLON = ":".charCodeAt(0).toString(16).toUpperCase();
38+
export const ESCAPED_COLON: string = ":".charCodeAt(0).toString(16).toUpperCase();
3939

4040
// Square brackets need to be escaped, but eslint has a problem with that.
4141
/* eslint-disable-next-line no-useless-escape */
42-
export const SPECIAL_CHARACTERS_RE = /[ !"#$%&'()\[\]{|}<>*+,./;=?@^`~\\]/;
42+
export const SPECIAL_CHARACTERS_RE: RegExp = /[ !"#$%&'()\[\]{|}<>*+,./;=?@^`~\\]/;
4343

4444
/**
4545
* Escapes special characters used by CSS selector items.
@@ -354,7 +354,7 @@ function* candidatesGenerator(
354354
export function* selectorWithinRootGenerator(
355355
elements: Element[],
356356
root: ParentNode,
357-
rootSelector: CssSelector = "",
357+
rootSelector: CssSelector | undefined = "",
358358
options: CssSelectorGeneratorOptions,
359359
): IterableIterator<CssSelector, undefined> {
360360
const elementSelectorsIterator = allSelectorsGenerator(elements, options);
@@ -375,7 +375,7 @@ export function* selectorWithinRootGenerator(
375375
export function* closestIdentifiableParentGenerator(
376376
elements: Element[],
377377
root: ParentNode,
378-
rootSelector: CssSelector = "",
378+
rootSelector: CssSelector | undefined = "",
379379
options: CssSelectorGeneratorOptions,
380380
): IterableIterator<IdentifiableParent> {
381381
if (elements.length === 0) {

src/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function getCommonParent(needle: Element[]): Element | null {
3434
/**
3535
* Yields all common parents of the needle, starting with the one closest to the needle.
3636
*/
37-
export function* parentsGenerator(needle: Element[], root?: ParentNode) {
37+
export function* parentsGenerator(needle: Element[], root?: ParentNode): Generator<Element, void, unknown> {
3838
let parent = getCommonParent(needle);
3939
while (parent && root?.contains(parent)) {
4040
yield parent;
@@ -49,7 +49,7 @@ export function* viableParentsGenerator(
4949
needle: Element[],
5050
needleSelector: string,
5151
root?: ParentNode,
52-
) {
52+
): Generator<Element, void, unknown> {
5353
for (const parentCandidate of parentsGenerator(needle, root)) {
5454
if (testSelector(needle, needleSelector, parentCandidate)) {
5555
yield parentCandidate;

tsconfig.base.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"noImplicitAny": true,
66
"module": "es6",
77
"target": "es6",
8-
"allowJs": true,
98
"sourceMap": true,
109
"moduleResolution": "node",
1110
"lib": ["ES6", "DOM", "DOM.Iterable"],
1211
"strict": true,
13-
"erasableSyntaxOnly": true
12+
"erasableSyntaxOnly": true,
13+
"isolatedDeclarations": true
1414
}
1515
}

0 commit comments

Comments
 (0)