Skip to content

Commit 8813c62

Browse files
committed
[eslint] add linting
1 parent cc94786 commit 8813c62

File tree

6 files changed

+43
-9
lines changed

6 files changed

+43
-9
lines changed

.eslintrc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"root": true,
3+
4+
"extends": "@ljharb",
5+
6+
"rules": {
7+
"id-length": "off",
8+
"new-cap": ["error", {
9+
"capIsNewExceptions": [
10+
"StringCharCodeAt",
11+
"RequireObjectCoercible",
12+
"ToInteger",
13+
"ToString",
14+
],
15+
}],
16+
"no-magic-numbers": "off",
17+
},
18+
19+
"overrides": [
20+
{
21+
"files": ["tests/**/*"],
22+
"rules": {
23+
"max-lines-per-function": "off",
24+
"max-statements-per-line": "off",
25+
},
26+
},
27+
]
28+
}

auto.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/*! https://mths.be/codepointat v1.0.0 by @mathias */
22

3+
'use strict';
4+
35
require('./shim')();

implementation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ module.exports = function codePointAt(position) {
2121
var first = StringCharCodeAt(string, index);
2222
var second;
2323
if ( // check if it’s the start of a surrogate pair
24-
first >= 0xD800 && first <= 0xDBFF && // high surrogate
25-
size > index + 1 // there is a next code unit
24+
first >= 0xD800 && first <= 0xDBFF // high surrogate
25+
&& size > index + 1 // there is a next code unit
2626
) {
2727
second = StringCharCodeAt(string, index + 1);
2828
if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
2929
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
30-
return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
30+
return ((first - 0xD800) * 0x400) + second - 0xDC00 + 0x10000;
3131
}
3232
}
3333
return first;

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
},
3131
"bugs": "https://github.com/mathiasbynens/String.prototype.codePointAt/issues",
3232
"scripts": {
33-
"pretest": "es-shim-api --bound",
33+
"lint": "eslint --ext=js,mjs .",
34+
"postlint": "es-shim-api --bound",
35+
"pretest": "npm run lint",
3436
"test": "npm run tests-only",
3537
"tests-only": "tape 'tests/*.js'",
3638
"posttest": "npx npm@'>=10.2' audit --production",
@@ -41,7 +43,9 @@
4143
},
4244
"devDependencies": {
4345
"@es-shims/api": "^2.5.1",
46+
"@ljharb/eslint-config": "^21.1.1",
4447
"define-properties": "^1.2.1",
48+
"eslint": "=8.8.0",
4549
"function-bind": "^1.1.2",
4650
"functions-have-names": "^1.2.3",
4751
"has-strict-mode": "^1.0.1",

shim.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ module.exports = function shimCodePointAt() {
1414
}
1515

1616
return polyfill;
17-
}
17+
};

tests/tests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var supportsStrictMode = require('has-strict-mode')();
44

5-
module.exports = function (codePointAt, t) {
5+
module.exports = function (codePointAt, t) {
66
t.test('String that starts with a BMP symbol', function (st) {
77
st.equal(codePointAt('abc\uD834\uDF06def', -1), undefined);
88
st.equal(codePointAt('abc\uD834\uDF06def', -0), 0x61);
@@ -89,14 +89,14 @@ module.exports = function (codePointAt, t) {
8989
st['throws'](function () { return codePointAt(null, 'a'); }, TypeError, 'null is not an object');
9090
st.end();
9191
});
92-
92+
9393
t.test('cast this value', function (st) {
9494
st.equal(codePointAt(42, 0), 0x34);
9595
st.equal(codePointAt(42, 1), 0x32);
96-
st.equal(codePointAt({ 'toString': function() { return 'abc'; } }, 2), 0x63);
96+
st.equal(codePointAt({ toString: function () { return 'abc'; } }, 2), 0x63);
9797

9898
var tmp = 0;
99-
st.equal(codePointAt({ 'toString': function() { ++tmp; return String(tmp); } }, 0), 0x31);
99+
st.equal(codePointAt({ toString: function () { tmp += 1; return String(tmp); } }, 0), 0x31);
100100
st.equal(tmp, 1);
101101

102102
st.end();

0 commit comments

Comments
 (0)