Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'eslint-scope' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
TSModuleDeclaration(node) {
const astRoot = this.scopeManager.globalScope.block;
const scope = this.currentScope();
const { id, body } = node;
// https://github.com/JamesHenry/typescript-estree/issues/27
if (isGlobalAugmentation(node, astRoot.tokens)) {
this.visitGlobalAugmentation(node);
return;
}
if (id && id.type === "Identifier") {
scope.__define(
id,
new Definition("NamespaceName", id, node, null, null, null)
);
}
this.visit(body);
}
TSEnumMember(node) {
const { id, initializer } = node;
const scope = this.currentScope();
scope.__define(id, new Definition("EnumMemberName", id, node));
// Set `eslintUsed` flag to the defined variable because the enum member is obviously exported.
const variable = scope.set.get(id.name);
variable.eslintUsed = true;
if (initializer) {
scope.__referencing(
id,
Reference.WRITE,
initializer,
null,
false,
true
);
this.visit(initializer);
}
TSEmptyBodyFunctionDeclaration(node) {
const upperTypeMode = this.typeMode;
const scope = this.currentScope();
const { id, typeParameters, params, returnType } = node;
// Ignore this if other overloadings have already existed.
const variable = scope.set.get(id.name);
const defs = variable && variable.defs;
const existed = defs && defs.some(d => d.type === "FunctionName");
if (!existed) {
scope.__define(
id,
new Definition("FunctionName", id, node, null, null, null)
);
}
// Find `typeof` expressions.
this.typeMode = true;
this.visit(typeParameters);
params.forEach(this.visit, this);
this.visit(returnType);
this.typeMode = upperTypeMode;
}
TSEmptyBodyDeclareFunction(node) {
TSEnumMember(node) {
const { id, initializer } = node;
const scope = this.currentScope();
scope.__define(id, new Definition("EnumMemberName", id, node));
// Set `eslintUsed` flag to the defined variable because the enum member is obviously exported.
const variable = scope.set.get(id.name);
variable.eslintUsed = true;
if (initializer) {
scope.__referencing(
id,
Reference.WRITE,
initializer,
null,
false,
true
);
this.visit(initializer);
}
}
// parse global comments and modify config
if (allowInlineConfig !== false) {
const modifyConfigResult = modifyConfigsFromComments(filename, sourceCode.ast, config, this);
config = modifyConfigResult.config;
modifyConfigResult.problems.forEach(problem => problems.push(problem));
disableDirectives = modifyConfigResult.disableDirectives;
} else {
disableDirectives = [];
}
const emitter = createEmitter();
const traverser = new Traverser();
const ecmaFeatures = config.parserOptions.ecmaFeatures || {};
const ecmaVersion = config.parserOptions.ecmaVersion || 5;
const scopeManager = eslintScope.analyze(sourceCode.ast, {
ignoreEval: true,
nodejsScope: ecmaFeatures.globalReturn,
impliedStrict: ecmaFeatures.impliedStrict,
ecmaVersion,
sourceType: config.parserOptions.sourceType || "script",
fallback: Traverser.getKeys
});
/*
* Create a frozen object with the ruleContext properties and methods that are shared by all rules.
* All rule contexts will inherit from this object. This avoids the performance penalty of copying all the
* properties once for each rule.
*/
const sharedTraversalContext = Object.freeze(
Object.assign(
Object.create(BASE_TRAVERSAL_CONTEXT),
for (var j = 0; j < node.typeParameters.params.length; j++) {
var name = node.typeParameters.params[j];
scope.__define(name, new Definition('TypeParameter', name, name));
if (name.typeAnnotation) {
checkIdentifierOrVisit.call(this, name);
}
}
scope.__define = function() {
return parentScope.__define.apply(parentScope, arguments);
};
return scope;
}
// visit decorators that are in: ClassDeclaration / ClassExpression
var { visitClass } = referencer.prototype;
referencer.prototype.visitClass = function(node) {
visitDecorators.call(this, node);
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
// visit flow type: ClassImplements
if (node.implements) {
for (var i = 0; i < node.implements.length; i++) {
checkIdentifierOrVisit.call(this, node.implements[i]);
}
}
if (node.superTypeParameters) {
for (var k = 0; k < node.superTypeParameters.params.length; k++) {
checkIdentifierOrVisit.call(this, node.superTypeParameters.params[k]);
}
}
createScopeVariable.call(this, node, node.id);
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
// TODO: Handle mixins
for (var i = 0; i < node.extends.length; i++) {
visitTypeAnnotation.call(this, node.extends[i]);
}
visitTypeAnnotation.call(this, node.body);
if (typeParamScope) {
this.close(node);
}
};
referencer.prototype.TypeAlias = function(node) {
createScopeVariable.call(this, node, node.id);
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
if (node.right) {
visitTypeAnnotation.call(this, node.right);
}
if (typeParamScope) {
this.close(node);
}
};
referencer.prototype.DeclareModule = referencer.prototype.DeclareFunction = referencer.prototype.DeclareVariable = referencer.prototype.DeclareClass = function(
node
) {
}
}
if (node.superTypeParameters) {
for (var k = 0; k < node.superTypeParameters.params.length; k++) {
checkIdentifierOrVisit.call(this, node.superTypeParameters.params[k]);
}
}
visitClass.call(this, node);
if (typeParamScope) {
this.close(node);
}
};
// visit decorators that are in: Property / MethodDefinition
var { visitProperty } = referencer.prototype;
referencer.prototype.visitProperty = function(node) {
if (node.value && node.value.type === 'TypeCastExpression') {
visitTypeAnnotation.call(this, node.value);
}
visitDecorators.call(this, node);
visitProperty.call(this, node);
};
function visitClassProperty(node) {
if (node.typeAnnotation) {
visitTypeAnnotation.call(this, node.typeAnnotation);
}
this.visitProperty(node);
}
// visit ClassProperty as a Property.
referencer.prototype.ClassProperty = visitClassProperty;
if (node.value && node.value.type === 'TypeCastExpression') {
visitTypeAnnotation.call(this, node.value);
}
visitDecorators.call(this, node);
visitProperty.call(this, node);
};
function visitClassProperty(node) {
if (node.typeAnnotation) {
visitTypeAnnotation.call(this, node.typeAnnotation);
}
this.visitProperty(node);
}
// visit ClassProperty as a Property.
referencer.prototype.ClassProperty = visitClassProperty;
// visit ClassPrivateProperty as a Property.
referencer.prototype.ClassPrivateProperty = visitClassProperty;
// visit flow type in FunctionDeclaration, FunctionExpression, ArrowFunctionExpression
var { visitFunction } = referencer.prototype;
referencer.prototype.visitFunction = function(node) {
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
if (node.returnType) {
checkIdentifierOrVisit.call(this, node.returnType);
}
// only visit if function parameters have types
if (node.params) {
visitDecorators.call(this, node);
visitProperty.call(this, node);
};
function visitClassProperty(node) {
if (node.typeAnnotation) {
visitTypeAnnotation.call(this, node.typeAnnotation);
}
this.visitProperty(node);
}
// visit ClassProperty as a Property.
referencer.prototype.ClassProperty = visitClassProperty;
// visit ClassPrivateProperty as a Property.
referencer.prototype.ClassPrivateProperty = visitClassProperty;
// visit flow type in FunctionDeclaration, FunctionExpression, ArrowFunctionExpression
var { visitFunction } = referencer.prototype;
referencer.prototype.visitFunction = function(node) {
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node);
}
if (node.returnType) {
checkIdentifierOrVisit.call(this, node.returnType);
}
// only visit if function parameters have types
if (node.params) {
for (var i = 0; i < node.params.length; i++) {
var param = node.params[i];
if (param.typeAnnotation) {