Software: Apache. PHP/8.1.30 uname -a: Linux server1.tuhinhossain.com 5.15.0-163-generic #173-Ubuntu SMP Tue Oct 14 17:51:00 UTC uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root) Safe-mode: OFF (not secure) /home/picotech/domains/rentals.picotech.app/public_html/node_modules/eslint/lib/rules/ drwxr-xr-x | |
| Viewing file: Select action/file-type: /**
* @fileoverview enforce default parameters to be last
* @author Chiawen Chen
*/
"use strict";
/**
* Checks if node is required: i.e. does not have a default value or ? optional indicator.
* @param {ASTNode} node the node to be evaluated
* @returns {boolean} true if the node is required, false if not.
*/
function isRequiredParameter(node) {
return !(
node.type === "AssignmentPattern" ||
node.type === "RestElement" ||
node.optional
);
}
/** @type {import('../types').Rule.RuleModule} */
module.exports = {
meta: {
dialects: ["javascript", "typescript"],
language: "javascript",
type: "suggestion",
docs: {
description: "Enforce default parameters to be last",
recommended: false,
frozen: true,
url: "https://eslint.org/docs/latest/rules/default-param-last",
},
schema: [],
messages: {
shouldBeLast: "Default parameters should be last.",
},
},
create(context) {
/**
* Handler for function contexts.
* @param {ASTNode} node function node
* @returns {void}
*/
function handleFunction(node) {
let hasSeenRequiredParameter = false;
for (let i = node.params.length - 1; i >= 0; i -= 1) {
const current = node.params[i];
const param =
current.type === "TSParameterProperty"
? current.parameter
: current;
if (isRequiredParameter(param)) {
hasSeenRequiredParameter = true;
continue;
}
if (hasSeenRequiredParameter) {
context.report({
node: current,
messageId: "shouldBeLast",
});
}
}
}
return {
FunctionDeclaration: handleFunction,
FunctionExpression: handleFunction,
ArrowFunctionExpression: handleFunction,
};
},
};
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0041 ]-- |