shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

Enhancement Request: warning on two functions defined with the same function name

Open scottdcoulter opened this issue 4 years ago • 1 comments

For new checks and feature suggestions

I'm running shellcheck 0.7.2.

I happened to notice that one of my scripts has two completely different definitions of functions with the same name. Presumably the one that is defined later in the file "wins", but it would be great if shellcheck could flag this duplicated function name.

Here's a snippet or screenshot that shows the problem:


#!/bin/ksh

## real script has a bunch of stuff here

function ee_join_column
{
   # Join column N with N+1 with ~ as separator
   #   Arguments: Column Number
   #   Input: Stream
   #   Output: Stream

   awk -v fn="$1" '{
      fs=",";
      f=split($0,b,fs);
      for (i=1;i<=f;i++)
      {
         if (i != fn+1) printf("%s",b[i]);
         if (i == fn) printf("~%s",b[i+1]);
         if (i < f && i != fn) printf(",");
      }
      printf("\n");
   }'
}

## real script has a bunch of stuff here

function ee_join_column
{
   # Join 2 Columns with provided separator and attach to end of file
   #   Arguments: Column Number 1, Column Number 2, Field Separator
   #   Input: Stream
   #   Output: Stream

   awk -v c1="$1" -v c2="$2" -v fj="$3" 'BEGIN { FS = OFS = "," }{
      printf("%s,%s%s%s\n",$0,$c1,fj,$c2);
   }'
}

## real script has a bunch of stuff here

Here's what shellcheck currently says:

No issues reported

Here's what I wanted or expected to see:

Warning: two functions defined with the same name.

scottdcoulter avatar Aug 31 '21 15:08 scottdcoulter

This PR attempts to fix it: https://github.com/koalaman/shellcheck/pull/2427

Jonta avatar Mar 10 '22 23:03 Jonta