Skip to content

Commit 0401701

Browse files
authored
chore(linter): prevent common errors (#252)
* setup linter * fix linter error * prevent console errors
1 parent 4e18941 commit 0401701

File tree

7 files changed

+57
-16
lines changed

7 files changed

+57
-16
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
"rollup-plugin-replace": "2.0.0",
6060
"rollup-plugin-terser": "1.0.1",
6161
"semantic-release": "15.5.0",
62+
"tslint": "5.10.0",
63+
"tslint-config-prettier": "1.13.0",
6264
"typescript": "2.8.3"
6365
},
6466
"keywords": [

src/compute.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { CustomScrollAction, Options } from './types'
2626
// @TODO better shadowdom test, 11 = document fragment
2727
const isElement = el =>
2828
el != null &&
29-
typeof el == 'object' &&
29+
typeof el === 'object' &&
3030
(el.nodeType === 1 || el.nodeType === 11)
3131

3232
const hasScrollableSpace = (el, axis: 'X' | 'Y') =>
@@ -91,7 +91,6 @@ const alignNearest = (
9191
* │┃ ┃│ do nothing
9292
* └───────────┘
9393
* ┗ ━ ━ ━ ━ ┛
94-
9594
*/
9695
if (
9796
(elementEdgeStart < scrollingEdgeStart &&
@@ -139,7 +138,6 @@ const alignNearest = (
139138
* ┃ │ ┃ │ ┃ ┃ │
140139
* └───────────┘ └───────────┘
141140
* ┗ ━ ━ ━ ━ ┛ ┗ ━ ━ ━ ━ ┛
142-
143141
*/
144142
if (
145143
(elementEdgeStart < scrollingEdgeStart && elementSize < scrollingSize) ||
@@ -213,13 +211,13 @@ export default (
213211
// The default behavior is to check if the current target matches the boundary element or not
214212
// If undefined it'll check that target is never undefined (can happen as we recurse up the tree)
215213
const checkBoundary =
216-
typeof boundary == 'function' ? boundary : parent => parent !== boundary
214+
typeof boundary === 'function' ? boundary : node => node !== boundary
217215

218216
if (!isElement(target)) {
219217
throw new Error('Element is required in scrollIntoView')
220218
}
221219

222-
let targetRect = target.getBoundingClientRect()
220+
const targetRect = target.getBoundingClientRect()
223221
const viewport = document.scrollingElement || document.documentElement
224222

225223
// Collect all the scrolling boxes, as defined in the spec: https://drafts.csswg.org/cssom-view/#scrolling-box

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ export interface Options<T = any> extends BaseOptions {
2222
let supportsScrollBehavior
2323
let scrollingElement
2424

25+
// tslint:disable-next-line: ban-types
2526
const isFunction = (arg: any): arg is Function => {
26-
return typeof arg == 'function'
27+
return typeof arg === 'function'
2728
}
2829
const isOptionsObject = <T>(options: any): options is T => {
2930
return options === Object(options) && Object.keys(options).length !== 0

src/types.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ export interface Options {
1616
}
1717

1818
// Custom behavior, not in any spec
19-
export interface CustomScrollBoundaryCallback {
20-
(parent: Element): boolean
21-
}
19+
export type CustomScrollBoundaryCallback = (parent: Element) => boolean
2220
export type CustomScrollBoundary = Element | CustomScrollBoundaryCallback
23-
export type CustomScrollAction = { el: Element; top: number; left: number }
24-
export interface CustomScrollBehaviorCallback<T> {
25-
(actions: CustomScrollAction[]): T
21+
export interface CustomScrollAction {
22+
el: Element
23+
top: number
24+
left: number
2625
}
26+
export type CustomScrollBehaviorCallback<T> = (
27+
actions: CustomScrollAction[]
28+
) => T

tests/web-platform/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"private": true,
33
"scripts": {
44
"browserstack": "wdio ./browserstack.conf.js",
5+
"lint": "tslint -c tslint.json 'src/**/*.ts'",
56
"start": "serve -i cypress/ -p 3000",
67
"test": "cypress run --browser chrome --reporter junit --reporter-options 'mochaFile=junit/test-results.xml'"
78
},

tslint.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"defaultSeverity": "error",
3+
"extends": ["tslint:recommended", "tslint-config-prettier"],
4+
"jsRules": {},
5+
"rules": {
6+
"interface-name": [true, "never-prefix"],
7+
"no-console": [true]
8+
},
9+
"rulesDirectory": []
10+
}

yarn.lock

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ buffer-from@^1.0.0:
11171117
version "1.0.0"
11181118
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.0.0.tgz#4cb8832d23612589b0406e9e2956c17f06fdf531"
11191119

1120-
builtin-modules@^1.0.0:
1120+
builtin-modules@^1.0.0, builtin-modules@^1.1.1:
11211121
version "1.1.1"
11221122
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"
11231123

@@ -1358,7 +1358,7 @@ [email protected]:
13581358
version "2.6.0"
13591359
resolved "https://registry.yarnpkg.com/commander/-/commander-2.6.0.tgz#9df7e52fb2a0cb0fb89058ee80c3104225f37e1d"
13601360

1361-
commander@^2.11.0, commander@^2.14.1, commander@^2.8.1, commander@^2.9.0:
1361+
commander@^2.11.0, commander@^2.12.1, commander@^2.14.1, commander@^2.8.1, commander@^2.9.0:
13621362
version "2.15.1"
13631363
resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"
13641364

@@ -3045,7 +3045,7 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
30453045
version "3.0.2"
30463046
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
30473047

3048-
js-yaml@^3.9.0, js-yaml@^3.9.1:
3048+
js-yaml@^3.7.0, js-yaml@^3.9.0, js-yaml@^3.9.1:
30493049
version "3.11.0"
30503050
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.11.0.tgz#597c1a8bd57152f26d622ce4117851a51f5ebaef"
30513051
dependencies:
@@ -5004,10 +5004,37 @@ trim-right@^1.0.1:
50045004
version "1.0.1"
50055005
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
50065006

5007-
tslib@^1.9.0:
5007+
tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
50085008
version "1.9.1"
50095009
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.1.tgz#a5d1f0532a49221c87755cfcc89ca37197242ba7"
50105010

5011+
5012+
version "1.13.0"
5013+
resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.13.0.tgz#189e821931ad89e0364e4e292d5c44a14e90ecd6"
5014+
5015+
5016+
version "5.10.0"
5017+
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.10.0.tgz#11e26bccb88afa02dd0d9956cae3d4540b5f54c3"
5018+
dependencies:
5019+
babel-code-frame "^6.22.0"
5020+
builtin-modules "^1.1.1"
5021+
chalk "^2.3.0"
5022+
commander "^2.12.1"
5023+
diff "^3.2.0"
5024+
glob "^7.1.1"
5025+
js-yaml "^3.7.0"
5026+
minimatch "^3.0.4"
5027+
resolve "^1.3.2"
5028+
semver "^5.3.0"
5029+
tslib "^1.8.0"
5030+
tsutils "^2.12.1"
5031+
5032+
tsutils@^2.12.1:
5033+
version "2.27.1"
5034+
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.27.1.tgz#ab0276ac23664f36ce8fd4414daec4aebf4373ee"
5035+
dependencies:
5036+
tslib "^1.8.1"
5037+
50115038
tunnel-agent@^0.6.0:
50125039
version "0.6.0"
50135040
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"

0 commit comments

Comments
 (0)