Skip to content

Commit d14764c

Browse files
committed
replace String#substr with String#slice and configure lint rule to enforce
1 parent f12e19e commit d14764c

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"imports": "always-multiline",
99
"exports": "always-multiline"
1010
}],
11+
"no-restricted-properties": ["error", {
12+
"property": "substr",
13+
"message": "Use String#slice instead."
14+
}],
1115
"max-len": [1, 120, 2],
1216
"spaced-comment": "off"
1317
}

gulp.d/tasks/build-preview-pages.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports =
4444
uiModel.page.attributes = Object.entries(doc.getAttributes())
4545
.filter(([name, val]) => name.startsWith('page-'))
4646
.reduce((accum, [name, val]) => {
47-
accum[name.substr(5)] = val
47+
accum[name.slice(5)] = val
4848
return accum
4949
}, {})
5050
uiModel.page.layout = doc.getAttribute('page-layout', 'default')
@@ -123,8 +123,8 @@ function relativize (to, { data: { root } }) {
123123
let hash = ''
124124
const hashIdx = to.indexOf('#')
125125
if (~hashIdx) {
126-
hash = to.substr(hashIdx)
127-
to = to.substr(0, hashIdx)
126+
hash = to.slice(hashIdx)
127+
to = to.slice(0, hashIdx)
128128
}
129129
return to === from
130130
? hash || (to.charAt(to.length - 1) === '/' ? './' : path.basename(to))
@@ -143,7 +143,7 @@ function transformHandlebarsError ({ message, stack }, layout) {
143143
const m = stack.match(/^ *at Object\.ret \[as (.+?)\]/m)
144144
const templatePath = `src/${m ? 'partials/' + m[1] : 'layouts/' + layout}.hbs`
145145
const err = new Error(`${message}${~message.indexOf('\n') ? '\n^ ' : ' '}in UI template ${templatePath}`)
146-
err.stack = [err.toString()].concat(stack.substr(message.length + 8)).join('\n')
146+
err.stack = [err.toString()].concat(stack.slice(message.length + 8)).join('\n')
147147
return err
148148
}
149149

gulp.d/tasks/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = (src, dest, preview) => () => {
3939
{
4040
filter: (asset) => new RegExp('^[~][^/]*(?:font|typeface)[^/]*/.*/files/.+[.](?:ttf|woff2?)$').test(asset.url),
4141
url: (asset) => {
42-
const relpath = asset.pathname.substr(1)
42+
const relpath = asset.pathname.slice(1)
4343
const abspath = require.resolve(relpath)
4444
const basename = ospath.basename(abspath)
4545
const destpath = ospath.join(dest, 'font', basename)

gulp.d/tasks/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict'
22

3-
const camelCase = (name) => name.replace(/[-]./g, (m) => m.substr(1).toUpperCase())
3+
const camelCase = (name) => name.replace(/[-]./g, (m) => m.slice(1).toUpperCase())
44

55
module.exports = require('require-directory')(module, __dirname, { recurse: false, rename: camelCase })

src/helpers/rearrange.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = (collection, property, orderSpec) => {
88
.map((it) => it.trim())
99
.filter((it) => {
1010
if (it.charAt() !== '!') return true
11-
sourceCollection.delete(it.substr(1))
11+
sourceCollection.delete(it.slice(1))
1212
})
1313
const restIdx = order.indexOf('*')
1414
if (~restIdx) order.splice(restIdx, 1)

0 commit comments

Comments
 (0)