Skip to content

Commit cafd4c0

Browse files
authored
chore: add object-shorthand eslint rule (#1159)
1 parent e34b370 commit cafd4c0

28 files changed

+169
-168
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default [
3131
rules: {
3232
"prefer-const": "error",
3333
"no-var": "error",
34+
"object-shorthand": "error",
3435
curly: ["error", "multi-line"],
3536
},
3637
},

src/lexer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Lexer.prototype.setInput = function (input) {
180180
first_encaps_node: false,
181181
// for backward compatible
182182
/* istanbul ignore next */
183-
toString: function () {
183+
toString() {
184184
this.label;
185185
},
186186
};

src/lexer/attribute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
module.exports = {
99
attributeIndex: 0,
1010
attributeListDepth: {},
11-
matchST_ATTRIBUTE: function () {
11+
matchST_ATTRIBUTE() {
1212
let ch = this.input();
1313
if (this.is_WHITESPACE()) {
1414
do {

src/lexer/comments.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
/*
1010
* Reads a single line comment
1111
*/
12-
T_COMMENT: function () {
12+
T_COMMENT() {
1313
while (this.offset < this.size) {
1414
const ch = this.input();
1515
if (ch === "\n" || ch === "\r") {
@@ -35,7 +35,7 @@ module.exports = {
3535
/*
3636
* Behaviour : https://github.com/php/php-src/blob/master/Zend/zend_language_scanner.l#L1927
3737
*/
38-
T_DOC_COMMENT: function () {
38+
T_DOC_COMMENT() {
3939
let ch = this.input();
4040
let token = this.tok.T_COMMENT;
4141
if (ch === "*") {

src/lexer/initial.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"use strict";
77

88
module.exports = {
9-
nextINITIAL: function () {
9+
nextINITIAL() {
1010
if (
1111
this.conditionStack.length > 1 &&
1212
this.conditionStack[this.conditionStack.length - 1] === "INITIAL"
@@ -18,7 +18,7 @@ module.exports = {
1818
}
1919
return this;
2020
},
21-
matchINITIAL: function () {
21+
matchINITIAL() {
2222
while (this.offset < this.size) {
2323
let ch = this.input();
2424
if (ch == "<") {

src/lexer/numbers.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (process.arch == "x64") {
1414
}
1515

1616
module.exports = {
17-
consume_NUM: function () {
17+
consume_NUM() {
1818
let ch = this.yytext[0];
1919
let hasPoint = ch === ".";
2020
if (ch === "0") {
@@ -124,7 +124,7 @@ module.exports = {
124124
}
125125
},
126126
// read hexa
127-
consume_HNUM: function () {
127+
consume_HNUM() {
128128
while (this.offset < this.size) {
129129
const ch = this.input();
130130
if (!this.is_HEX()) {
@@ -135,7 +135,7 @@ module.exports = {
135135
return this.tok.T_LNUMBER;
136136
},
137137
// read a generic number
138-
consume_LNUM: function () {
138+
consume_LNUM() {
139139
while (this.offset < this.size) {
140140
const ch = this.input();
141141
if (!this.is_NUM()) {
@@ -146,7 +146,7 @@ module.exports = {
146146
return this.tok.T_LNUMBER;
147147
},
148148
// read binary
149-
consume_BNUM: function () {
149+
consume_BNUM() {
150150
let ch;
151151
while (this.offset < this.size) {
152152
ch = this.input();
@@ -158,7 +158,7 @@ module.exports = {
158158
return this.tok.T_LNUMBER;
159159
},
160160
// read an octal number
161-
consume_ONUM: function () {
161+
consume_ONUM() {
162162
while (this.offset < this.size) {
163163
const ch = this.input();
164164
if (!this.is_OCTAL()) {

src/lexer/property.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"use strict";
77

88
module.exports = {
9-
matchST_LOOKING_FOR_PROPERTY: function () {
9+
matchST_LOOKING_FOR_PROPERTY() {
1010
let ch = this.input();
1111
if (ch === "-") {
1212
ch = this.input();
@@ -28,7 +28,7 @@ module.exports = {
2828
if (ch) this.unput(1);
2929
return false;
3030
},
31-
matchST_LOOKING_FOR_VARNAME: function () {
31+
matchST_LOOKING_FOR_VARNAME() {
3232
let ch = this.input();
3333

3434
// SHIFT STATE
@@ -52,7 +52,7 @@ module.exports = {
5252
// stops looking for a varname and starts the scripting mode
5353
return false;
5454
},
55-
matchST_VAR_OFFSET: function () {
55+
matchST_VAR_OFFSET() {
5656
const ch = this.input();
5757
if (this.is_NUM_START()) {
5858
this.consume_NUM();

src/lexer/scripting.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"use strict";
77

88
module.exports = {
9-
matchST_IN_SCRIPTING: function () {
9+
matchST_IN_SCRIPTING() {
1010
let ch = this.input();
1111
switch (ch) {
1212
case " ":
@@ -100,7 +100,7 @@ module.exports = {
100100
);
101101
},
102102

103-
T_WHITESPACE: function () {
103+
T_WHITESPACE() {
104104
while (this.offset < this.size) {
105105
const ch = this.input();
106106
if (ch === " " || ch === "\t" || ch === "\n" || ch === "\r") {

src/lexer/strings.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const valid_after_heredoc_73 = valid_after_heredoc.concat([
2020
]);
2121

2222
module.exports = {
23-
T_CONSTANT_ENCAPSED_STRING: function () {
23+
T_CONSTANT_ENCAPSED_STRING() {
2424
let ch;
2525
while (this.offset < this.size) {
2626
ch = this.input();
@@ -33,7 +33,7 @@ module.exports = {
3333
return this.tok.T_CONSTANT_ENCAPSED_STRING;
3434
},
3535
// check if matching a HEREDOC state
36-
is_HEREDOC: function () {
36+
is_HEREDOC() {
3737
const revert = this.offset;
3838
if (
3939
this._input[this.offset - 1] === "<" &&
@@ -97,7 +97,7 @@ module.exports = {
9797
this.offset = revert;
9898
return false;
9999
},
100-
ST_DOUBLE_QUOTES: function () {
100+
ST_DOUBLE_QUOTES() {
101101
let ch;
102102
while (this.offset < this.size) {
103103
ch = this.input();
@@ -141,7 +141,7 @@ module.exports = {
141141
},
142142

143143
// check if its a DOC end sequence
144-
isDOC_MATCH: function (offset, consumeLeadingSpaces) {
144+
isDOC_MATCH(offset, consumeLeadingSpaces) {
145145
// @fixme : check if out of text limits
146146

147147
// consumeLeadingSpaces is false happen DOC prematch END HEREDOC stage.
@@ -222,7 +222,7 @@ module.exports = {
222222
* Prematch the end of HEREDOC/NOWDOC end tag to preset the
223223
* context of this.heredoc_label
224224
*/
225-
prematch_ENDOFDOC: function () {
225+
prematch_ENDOFDOC() {
226226
// reset heredoc
227227
this.heredoc_label.indentation_uses_spaces = false;
228228
this.heredoc_label.indentation = 0;
@@ -249,7 +249,7 @@ module.exports = {
249249
}
250250
},
251251

252-
matchST_NOWDOC: function () {
252+
matchST_NOWDOC() {
253253
// edge case : empty now doc
254254
if (this.isDOC_MATCH(this.offset, true)) {
255255
// @fixme : never reached (may be caused by quotes)
@@ -275,7 +275,7 @@ module.exports = {
275275
return this.tok.T_ENCAPSED_AND_WHITESPACE;
276276
},
277277

278-
matchST_HEREDOC: function () {
278+
matchST_HEREDOC() {
279279
// edge case : empty here doc
280280
let ch = this.input();
281281
if (this.isDOC_MATCH(this.offset, true)) {
@@ -347,7 +347,7 @@ module.exports = {
347347
return this.tok.T_ENCAPSED_AND_WHITESPACE;
348348
},
349349

350-
consume_VARIABLE: function () {
350+
consume_VARIABLE() {
351351
this.consume_LABEL();
352352
const ch = this.input();
353353
if (ch == "[") {
@@ -371,7 +371,7 @@ module.exports = {
371371
return this.tok.T_VARIABLE;
372372
},
373373
// HANDLES BACKQUOTES
374-
matchST_BACKQUOTE: function () {
374+
matchST_BACKQUOTE() {
375375
let ch = this.input();
376376
if (ch === "$") {
377377
ch = this.input();
@@ -446,7 +446,7 @@ module.exports = {
446446
return this.tok.T_ENCAPSED_AND_WHITESPACE;
447447
},
448448

449-
matchST_DOUBLE_QUOTES: function () {
449+
matchST_DOUBLE_QUOTES() {
450450
let ch = this.input();
451451
if (ch === "$") {
452452
ch = this.input();

0 commit comments

Comments
 (0)