Skip to content

Commit c943235

Browse files
committed
Fixed bug in release 0.1.6
1 parent 8ae6436 commit c943235

2 files changed

Lines changed: 37 additions & 42 deletions

File tree

cfn_inline_lambda_linter/linter.py

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -95,49 +95,36 @@ def extractLambdaCode(resources, parameters, dict_to_check, args=None):
9595

9696
process = None # Initialize process variable
9797

98-
if "!Ref" in programming_lang or "Fn::Ref" in programming_lang:
99-
print(programming_lang)
100-
param = programming_lang.strip().split()[-1]
101-
print(param)
102-
if param in parameters:
103-
val = parameters[param]["Default"]
104-
if "python" in val:
105-
if args is None:
98+
# Check if runtime contains "python" directly
99+
if "python" in programming_lang:
100+
if args is None:
101+
process = subprocess.Popen(
102+
['python', '-m', 'flake8', "-", "--ignore=F821"],
103+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
104+
)
105+
else:
106+
if "F821" in args:
107+
process = subprocess.Popen(
108+
['python', '-m', 'flake8', "-"] + args.split(),
109+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
110+
)
111+
else:
112+
if "--ignore" in args:
113+
y=args.split("--ignore=")[1] + ",F821"
114+
z=args.split("--ignore")[:-1] + ["--ignore=" + y]
106115
process = subprocess.Popen(
107-
['python', '-m', 'flake8', "-", "--ignore=F821"],
116+
['python', '-m', 'flake8', "-"] + z,
108117
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
109118
)
110119
else:
111-
if "F821" in args:
112-
process = subprocess.Popen(
113-
['python', '-m', 'flake8', "-"] + args.split(),
114-
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
115-
)
116-
else:
117-
if "--ignore" in args:
118-
y=args.split("--ignore=")[1] + ",F821"
119-
z=args.split("--ignore")[:-1] + ["--ignore=" + y]
120-
process = subprocess.Popen(
121-
['python', '-m', 'flake8', "-"] + z,
122-
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
123-
)
124-
else:
125-
process = subprocess.Popen(
126-
['python', '-m', 'flake8', "-", "--ignore=F821"] + args.split(),
127-
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
128-
)
129-
else:
130-
print(f"❌ Found a programming language that is not supported at the moment")
131-
dict_to_check[i] = {
132-
"status": "SkippingLambda",
133-
"errors": f"Unsupported programming language: {val}"
134-
}
135-
print(Fore.GREEN + f"✅ Linting check completed for resource '{i}'" + Style.RESET_ALL)
136-
continue
137-
else:
138-
raise KeyError(f"❌ Parameter definition for parameter {param} is missing")
139-
elif ("!Ref" not in programming_lang and "Fn::Ref" not in programming_lang):
140-
if "python" in programming_lang:
120+
process = subprocess.Popen(
121+
['python', '-m', 'flake8', "-", "--ignore=F821"] + args.split(),
122+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
123+
)
124+
# Check if runtime is a parameter name (CloudFormation reference resolved)
125+
elif programming_lang in parameters:
126+
val = parameters[programming_lang]["Default"]
127+
if "python" in val:
141128
if args is None:
142129
process = subprocess.Popen(
143130
['python', '-m', 'flake8', "-", "--ignore=F821"],
@@ -163,13 +150,21 @@ def extractLambdaCode(resources, parameters, dict_to_check, args=None):
163150
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
164151
)
165152
else:
166-
print(f" Found a programming language that is not supported at the moment")
153+
print(f"⚠️ Found a programming language that is not supported at the moment")
167154
dict_to_check[i] = {
168155
"status": "SkippingLambda",
169-
"errors": f"Unsupported programming language: {programming_lang}"
156+
"errors": f"Unsupported programming language: {val}"
170157
}
171158
print(Fore.GREEN + f"✅ Linting check completed for resource '{i}'" + Style.RESET_ALL)
172159
continue
160+
else:
161+
print(f"⚠️ Found a programming language that is not supported at the moment")
162+
dict_to_check[i] = {
163+
"status": "SkippingLambda",
164+
"errors": f"Unsupported programming language: {programming_lang}"
165+
}
166+
print(Fore.GREEN + f"✅ Linting check completed for resource '{i}'" + Style.RESET_ALL)
167+
continue
173168

174169
# Only proceed with linting if we have a valid process
175170
if process is not None:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cfn-inline-lambda-linter"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
description = "Prints out linting errors found in inline cloudformation lambda code"
55
authors = ["Saad Mohsin Khan <saadk687@gmail.com>"]
66
license = "MIT"

0 commit comments

Comments
 (0)