Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit be831b5

Browse files
authored
UNDOCUMENTED -PR #2 from glenn2223
Lint fixes
2 parents 958df26 + 0bdb391 commit be831b5

File tree

3 files changed

+179
-175
lines changed

3 files changed

+179
-175
lines changed

.eslintrc.json

+109-113
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,111 @@
11
{
2-
"root": true,
3-
"env": {
4-
"browser": true,
5-
"commonjs": true,
6-
"es2021": true,
7-
"node": true
8-
},
9-
"extends": [
10-
"eslint:recommended",
11-
"plugin:@typescript-eslint/recommended"
12-
],
13-
"parser": "@typescript-eslint/parser",
14-
"parserOptions": {
15-
"ecmaVersion": 12
16-
},
17-
"plugins": [
18-
"@typescript-eslint"
19-
],
20-
"rules": {
21-
"@typescript-eslint/naming-convention": [
22-
"warn",
23-
{
24-
"selector": "function",
25-
"format": "camelCase"
26-
}
27-
],
28-
"@typescript-eslint/semi": "warn",
29-
"semi": "warn",
30-
"getter-return": "warn",
31-
"no-dupe-args" :"warn",
32-
"no-dupe-else-if": "warn",
33-
"no-dupe-keys": "warn",
34-
"no-duplicate-case": "warn",
35-
"no-empty": "warn",
36-
"accessor-pairs": "warn",
37-
"array-callback-return": "warn",
38-
"block-scoped-var": "warn",
39-
"class-methods-use-this": "warn",
40-
"complexity": "warn",
41-
"consistent-return": "warn",
42-
"curly": "warn",
43-
"default-case": "warn",
44-
"default-case-last": "warn",
45-
"default-param-last": "warn",
46-
"dot-location": "off",
47-
"dot-notation": "warn",
48-
"eqeqeq": "warn",
49-
"grouped-accessor-pairs": "warn",
50-
"guard-for-in": "off",
51-
"max-classes-per-file": ["warn", 2],
52-
"no-alert": "warn",
53-
"no-caller": "warn",
54-
"no-case-declarations": "off",
55-
"no-constructor-return": "warn",
56-
"no-div-regex": "warn",
57-
"no-else-return": "warn",
58-
"no-empty-function": "warn",
59-
"no-empty-pattern": "warn",
60-
"no-eq-null": "warn",
61-
"no-eval": "warn",
62-
"no-extend-native": "off",
63-
"no-extra-bind": "warn",
64-
"no-extra-label": "warn",
65-
"no-fallthrough": "warn",
66-
"no-floating-decimal": "warn",
67-
"no-global-assign": "warn",
68-
"no-implicit-coercion": "warn",
69-
"no-implicit-globals": "warn",
70-
"no-implied-eval": "warn",
71-
"no-invalid-this": "off",
72-
"no-iterator": "warn",
73-
"no-labels": "warn",
74-
"no-lone-blocks": "warn",
75-
"no-loop-func": "warn",
76-
"no-magic-numbers": "off",
77-
"no-multi-spaces": "warn",
78-
"no-multi-str": "warn",
79-
"no-new": "warn",
80-
"no-new-func": "warn",
81-
"no-new-wrappers": "warn",
82-
"no-octal": "warn",
83-
"no-octal-escape": "warn",
84-
"no-param-reassign": "warn",
85-
"no-proto": "warn",
86-
"no-redeclare": "off",
87-
"no-restricted-properties": "warn",
88-
"no-return-assign": "warn",
89-
"no-return-await": "warn",
90-
"no-script-url": "warn",
91-
"no-self-assign": "warn",
92-
"no-self-compare": "warn",
93-
"no-sequences": "warn",
94-
"no-throw-literal": "warn",
95-
"no-unmodified-loop-condition": "warn",
96-
"no-unused-expressions": "warn",
97-
"no-unused-labels": "warn",
98-
"no-useless-call": "warn",
99-
"no-useless-catch": "warn",
100-
"no-useless-concat": "warn",
101-
"no-useless-escape": "warn",
102-
"no-useless-return": "warn",
103-
"no-void": "warn",
104-
"no-warning-comments": "warn",
105-
"no-with": "warn",
106-
"prefer-named-capture-group": "warn",
107-
"prefer-promise-reject-errors": "off",
108-
"prefer-regex-literals": "warn",
109-
"radix": "warn",
110-
"require-await": "warn",
111-
"require-unicode-regexp": "off",
112-
"vars-on-top": "warn",
113-
"wrap-iife": "warn"
114-
}
2+
"root": true,
3+
"env": {
4+
"browser": true,
5+
"commonjs": true,
6+
"es2021": true,
7+
"node": true
8+
},
9+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
10+
"parser": "@typescript-eslint/parser",
11+
"parserOptions": {
12+
"ecmaVersion": 12
13+
},
14+
"plugins": ["@typescript-eslint"],
15+
"rules": {
16+
"@typescript-eslint/naming-convention": [
17+
"warn",
18+
{
19+
"selector": "function",
20+
"format": ["camelCase"]
21+
}
22+
],
23+
"@typescript-eslint/semi": "warn",
24+
"semi": "off",
25+
"getter-return": "warn",
26+
"no-dupe-args": "warn",
27+
"no-dupe-else-if": "warn",
28+
"no-dupe-keys": "warn",
29+
"no-duplicate-case": "warn",
30+
"no-empty": "warn",
31+
"accessor-pairs": "warn",
32+
"array-callback-return": "warn",
33+
"block-scoped-var": "warn",
34+
"class-methods-use-this": "warn",
35+
"complexity": "warn",
36+
"consistent-return": "warn",
37+
"curly": "warn",
38+
"default-case": "warn",
39+
"default-case-last": "warn",
40+
"default-param-last": "warn",
41+
"dot-location": "off",
42+
"dot-notation": "warn",
43+
"eqeqeq": "warn",
44+
"grouped-accessor-pairs": "warn",
45+
"guard-for-in": "off",
46+
"max-classes-per-file": ["warn", 2],
47+
"no-alert": "warn",
48+
"no-caller": "warn",
49+
"no-case-declarations": "off",
50+
"no-constructor-return": "warn",
51+
"no-div-regex": "warn",
52+
"no-else-return": "warn",
53+
"no-empty-function": "warn",
54+
"no-empty-pattern": "warn",
55+
"no-eq-null": "warn",
56+
"no-eval": "warn",
57+
"no-extend-native": "off",
58+
"no-extra-bind": "warn",
59+
"no-extra-label": "warn",
60+
"no-fallthrough": "warn",
61+
"no-floating-decimal": "warn",
62+
"no-global-assign": "warn",
63+
"no-implicit-coercion": "warn",
64+
"no-implicit-globals": "warn",
65+
"no-implied-eval": "warn",
66+
"no-invalid-this": "off",
67+
"no-iterator": "warn",
68+
"no-labels": "warn",
69+
"no-lone-blocks": "warn",
70+
"no-loop-func": "warn",
71+
"no-magic-numbers": "off",
72+
"no-mixed-spaces-and-tabs": [ "warn", "smart-tabs" ],
73+
"no-multi-spaces": "warn",
74+
"no-multi-str": "warn",
75+
"no-new": "warn",
76+
"no-new-func": "warn",
77+
"no-new-wrappers": "warn",
78+
"no-octal": "warn",
79+
"no-octal-escape": "warn",
80+
"no-param-reassign": "warn",
81+
"no-proto": "warn",
82+
"no-redeclare": "off",
83+
"no-restricted-properties": "warn",
84+
"no-return-assign": "warn",
85+
"no-return-await": "warn",
86+
"no-script-url": "warn",
87+
"no-self-assign": "warn",
88+
"no-self-compare": "warn",
89+
"no-sequences": "warn",
90+
"no-throw-literal": "warn",
91+
"no-unmodified-loop-condition": "warn",
92+
"no-unused-expressions": "warn",
93+
"no-unused-labels": "warn",
94+
"no-useless-call": "warn",
95+
"no-useless-catch": "warn",
96+
"no-useless-concat": "warn",
97+
"no-useless-escape": "warn",
98+
"no-useless-return": "warn",
99+
"no-void": "warn",
100+
"no-warning-comments": "warn",
101+
"no-with": "warn",
102+
"prefer-named-capture-group": "warn",
103+
"prefer-promise-reject-errors": "off",
104+
"prefer-regex-literals": "warn",
105+
"radix": "warn",
106+
"require-await": "warn",
107+
"require-unicode-regexp": "off",
108+
"vars-on-top": "warn",
109+
"wrap-iife": "warn"
110+
}
115111
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"test": "echo \"Error: no test specified\" && exit 1",
2929
"build": "tsc",
3030
"format": "prettier --write \"src/**/*.ts\"",
31-
"lint": "eslint . --ext .ts",
31+
"lint": "eslint ./src --ext .ts",
3232
"prepare": "npm run build",
3333
"prepublishOnly": "npm run lint"
3434
},

src/index.ts

+69-61
Original file line numberDiff line numberDiff line change
@@ -115,66 +115,7 @@ export class HoverPosition {
115115
return { top: myFits[0].top.value, left: myFits[0].left.value };
116116
}
117117

118-
const parsedMy = HoverPosition.parse(my),
119-
parsedAt = HoverPosition.parse(at);
120-
121-
const bestAltHorizFits = myFits.filter(
122-
(f) => f.my.startsWith(parsedMy.vertical + ' ') && f.at.startsWith(parsedAt.vertical + ' '),
123-
);
124-
125-
const bestAltVertFits = myFits.filter(
126-
(f) => f.my.endsWith(' ' + parsedMy.horizontal) && f.at.endsWith(' ' + parsedAt.horizontal),
127-
);
128-
129-
if (bestAltVertFits.length > 0 && bestAltHorizFits.length > 0) {
130-
myFits = options.bestFitPreference === 'vertical' ? bestAltVertFits : bestAltHorizFits;
131-
} else if (bestAltVertFits.length > 0) {
132-
myFits = bestAltVertFits;
133-
} else if (bestAltHorizFits.length > 0) {
134-
myFits = bestAltHorizFits;
135-
} else {
136-
if (options.bestFitPreference === 'vertical') {
137-
// If it's center then we don't care about overlay. Infact, it's prefered!
138-
const bothCenter = parsedMy.horizontal === 'center' && parsedAt.horizontal === 'center',
139-
flippedMy = bothCenter
140-
? 'left' // <= Does pushing to the left fit?
141-
: HoverPosition.flipAlignment(parsedMy.horizontal),
142-
flippedAt = bothCenter
143-
? 'left' // <= Does pushing to the left fit?
144-
: HoverPosition.flipAlignment(parsedMy.horizontal);
145-
146-
myFits = myFits.filter((f) => f.my.endsWith(' ' + flippedMy) && f.at.endsWith(' ' + flippedAt));
147-
148-
if (myFits.length === 0 && bothCenter) {
149-
// What about to the right?
150-
myFits = myFits.filter(
151-
(f) =>
152-
f.my.endsWith(' ' + HoverPosition.flipAlignment(flippedMy)) &&
153-
f.at.endsWith(' ' + HoverPosition.flipAlignment(flippedAt)),
154-
);
155-
}
156-
} else {
157-
// If it's center then we don't care about overlay. Infact, it's prefered!
158-
const bothCenter = parsedMy.vertical === 'center' && parsedAt.vertical === 'center',
159-
flippedMy = bothCenter
160-
? 'top' // <= Does pushing to the top fit?
161-
: HoverPosition.flipAlignment(parsedMy.vertical),
162-
flippedAt = bothCenter
163-
? 'top' // <= Does pushing to the top fit?
164-
: HoverPosition.flipAlignment(parsedMy.vertical);
165-
166-
myFits = myFits.filter((f) => f.my.startsWith(flippedMy + ' ') && f.at.startsWith(flippedAt + ' '));
167-
168-
if (myFits.length === 0 && bothCenter) {
169-
// What about to the bottom?
170-
myFits = myFits.filter(
171-
(f) =>
172-
f.my.startsWith(HoverPosition.flipAlignment(flippedMy) + ' ') &&
173-
f.at.startsWith(HoverPosition.flipAlignment(flippedAt) + ' '),
174-
);
175-
}
176-
}
177-
}
118+
myFits = HoverPosition.findBestFits(my, at, options, myFits);
178119

179120
if (myFits.length === 0) {
180121
return { top: fitData.top.value, left: fitData.left.value };
@@ -360,12 +301,79 @@ export class HoverPosition {
360301
}
361302

362303
private static flip(old: CombinedAlignment): CombinedAlignment {
363-
var parsedOld = HoverPosition.parse(old);
304+
const parsedOld = HoverPosition.parse(old);
364305

365306
return `${HoverPosition.flipAlignment(parsedOld.vertical)} ${HoverPosition.flipAlignment(
366307
parsedOld.horizontal,
367308
)}` as CombinedAlignment;
368309
}
310+
311+
private static findBestFits(my: CombinedAlignment, at: CombinedAlignment, options: Options, inFitData: FitPositionData[]): FitPositionData[] {
312+
const parsedMy = HoverPosition.parse(my),
313+
parsedAt = HoverPosition.parse(at);
314+
315+
let bestFits: FitPositionData[];
316+
317+
const bestAltHorizFits = inFitData.filter(
318+
(f) => f.my.startsWith(parsedMy.vertical + ' ') && f.at.startsWith(parsedAt.vertical + ' '),
319+
);
320+
321+
const bestAltVertFits = inFitData.filter(
322+
(f) => f.my.endsWith(' ' + parsedMy.horizontal) && f.at.endsWith(' ' + parsedAt.horizontal),
323+
);
324+
325+
if (bestAltVertFits.length > 0 && bestAltHorizFits.length > 0) {
326+
bestFits = options.bestFitPreference === 'vertical' ? bestAltVertFits : bestAltHorizFits;
327+
} else if (bestAltVertFits.length > 0) {
328+
bestFits = bestAltVertFits;
329+
} else if (bestAltHorizFits.length > 0) {
330+
bestFits = bestAltHorizFits;
331+
} else {
332+
if (options.bestFitPreference === 'vertical') {
333+
// If it's center then we don't care about overlay. Infact, it's prefered!
334+
const bothCenter = parsedMy.horizontal === 'center' && parsedAt.horizontal === 'center',
335+
flippedMy = bothCenter
336+
? 'left' // <= Does pushing to the left fit?
337+
: HoverPosition.flipAlignment(parsedMy.horizontal),
338+
flippedAt = bothCenter
339+
? 'left' // <= Does pushing to the left fit?
340+
: HoverPosition.flipAlignment(parsedMy.horizontal);
341+
342+
bestFits = inFitData.filter((f) => f.my.endsWith(' ' + flippedMy) && f.at.endsWith(' ' + flippedAt));
343+
344+
if (bestFits.length === 0 && bothCenter) {
345+
// What about to the right?
346+
bestFits = inFitData.filter(
347+
(f) =>
348+
f.my.endsWith(' ' + HoverPosition.flipAlignment(flippedMy)) &&
349+
f.at.endsWith(' ' + HoverPosition.flipAlignment(flippedAt)),
350+
);
351+
}
352+
} else {
353+
// If it's center then we don't care about overlay. Infact, it's prefered!
354+
const bothCenter = parsedMy.vertical === 'center' && parsedAt.vertical === 'center',
355+
flippedMy = bothCenter
356+
? 'top' // <= Does pushing to the top fit?
357+
: HoverPosition.flipAlignment(parsedMy.vertical),
358+
flippedAt = bothCenter
359+
? 'top' // <= Does pushing to the top fit?
360+
: HoverPosition.flipAlignment(parsedMy.vertical);
361+
362+
bestFits = inFitData.filter((f) => f.my.startsWith(flippedMy + ' ') && f.at.startsWith(flippedAt + ' '));
363+
364+
if (bestFits.length === 0 && bothCenter) {
365+
// What about to the bottom?
366+
bestFits = inFitData.filter(
367+
(f) =>
368+
f.my.startsWith(HoverPosition.flipAlignment(flippedMy) + ' ') &&
369+
f.at.startsWith(HoverPosition.flipAlignment(flippedAt) + ' '),
370+
);
371+
}
372+
}
373+
}
374+
375+
return bestFits;
376+
}
369377
}
370378

371379
export type PositionAlignment = types.PositionAlignment;

0 commit comments

Comments
 (0)