all-flags-state

Try in Playground
python-launchdarklyBest PracticeInformational

0

No tags

No CWE or CVE

Ensure that the all_flags_state() function is correctly used.

See official LaunchDarkly documentation

Ast Rule: function call


all-flags-state

How to write a rule
function visit(node, filename, code) {
	if(node.functionName.value !== "all_flags_state") {
    
    return;
  }
  const functionNameNode = node.functionName;

  if(node.arguments && node.arguments.values && node.arguments.values.length !== 1){
    const error = buildError(functionNameNode.start.line, functionNameNode.start.col, 
                             functionNameNode.end.line, functionNameNode.end.col, 
                             "function all_flags_state() takes one argument (a user)", "MINOR", "BEST_PRACTICES");
    const edit = buildEditAdd(node.end.line, node.end.col, "user")
    const fix = buildFix("add user argument", [edit]);
          
    addError(error.addFix(fix));
  }
  
  if(node.arguments && node.arguments.values && node.arguments.values.length === 1) {
    const firstArgument = node.arguments.values[0];
    if(firstArgument.value.value.startsWith("\"") || firstArgument.value.value.startsWith("f\"")) {
      const error = buildError(firstArgument.start.line, firstArgument.start.col, 
                               firstArgument.end.line, firstArgument.end.col, 
                               "argument should be a user, not a string", "MINOR", "BEST_PRACTICES");
      addError(error);
    }
  }
}

argument-with-string.py

Expected test result: has error

state = ldclient.get().all_flags_state("foo")

two-arguments.py

Expected test result: has error

state = ldclient.get().all_flags_state(user, foo)
Add comment

Log in to add a comment


    Be the first one to leave a comment!

Codiga Logo
Codiga Hub
  • Rulesets
  • Playground
  • Snippets
  • Cookbooks
Legal
  • Security
  • Privacy Policy
  • Code Privacy
  • Terms of Service
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.