Skip to content

Commit 0bd92a2

Browse files
Create BE_FE_Linter.py
Python script added
1 parent f31e44e commit 0bd92a2

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

BE_FE_Linter.py

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/python
2+
import os
3+
import subprocess
4+
5+
def prRed(skk): print("\033[91m {}\033[00m" .format(skk))
6+
def prGreen(skk): print("\033[92m {}\033[00m" .format(skk))
7+
def prYellow(skk): print("\033[93m {}\033[00m" .format(skk))
8+
def prLightPurple(skk): print("\033[94m {}\033[00m" .format(skk))
9+
def prPurple(skk): print("\033[95m {}\033[00m" .format(skk))
10+
def prCyan(skk): print("\033[96m {}\033[00m" .format(skk))
11+
def prLightGray(skk): print("\033[97m {}\033[00m" .format(skk))
12+
def prBlack(skk): print("\033[98m {}\033[00m" .format(skk))
13+
14+
def runLinter( ):
15+
os.environ['PATH']
16+
stream = os.popen(r'git status | grep "new file:\|modified:"')
17+
changedFileList = stream.readlines()
18+
prCyan("\nLinting process started for changed javascript and ruby files......\n\n")
19+
print(stream.read())
20+
21+
'''
22+
i.e Let's say, from your root of the project, after doing git status, you see list of changed files
23+
client/app/parent/components/molecules/ComponentFolder/Component.js
24+
then you have check based on your codebase, for what file path yarn eslint works,
25+
26+
Let's say, it works for
27+
yarn eslint client/app/parent/components/molecules/ComponentFolder/Component.js
28+
then 'parent/' will be the starting folder.
29+
30+
'''
31+
startingFolder = r'app/' # Actual file path starting folder
32+
33+
frontendStreamList = []
34+
backendStreamList = []
35+
for changedFile in changedFileList:
36+
startingFolderIndex = changedFile.find(startingFolder)
37+
if (startingFolderIndex > -1):
38+
actualFilePath = changedFile[startingFolderIndex:len(changedFile) - 1]
39+
fileType = actualFilePath.lower()
40+
if(fileType.endswith(".js") or fileType.endswith(".ts") or fileType.endswith(".tsx") ):
41+
feStreams = os.popen(r'cd client;yarn eslint ' + actualFilePath + r';cd ..;')# We can modify this command based on our requirement to lint frontend files.
42+
frontendStreamList.append(feStreams)
43+
elif (fileType.endswith('.rb')):
44+
beSreams = os.popen(r'rubocop --config .rubocop/test.yml ' + actualFilePath) # We can modify this command based on our requirement to lint backend files.
45+
backendStreamList.append(beSreams)
46+
47+
prGreen("FRONTEND FILES PROCESS RESULTS:")
48+
prGreen("================================\n")
49+
count = 0
50+
if(len(frontendStreamList) > 0):
51+
for festream in frontendStreamList:
52+
count = int(count) + 1
53+
prGreen(str(count) + ': ')
54+
print(festream.read())
55+
else:
56+
prBlack("No frontend files to do linting process.")
57+
58+
print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
59+
prRed("BACKEND FILES PROCESS RESULTS:")
60+
prRed("================================\n")
61+
totalFeBeFileCount = count
62+
if(len(backendStreamList) > 0):
63+
count = 0
64+
for bestream in backendStreamList:
65+
count = int(count) + 1
66+
prRed(str(count) + ': ')
67+
print(bestream.read())
68+
else:
69+
prBlack("No backend files to do linting process.\n")
70+
totalFeBeFileCount += count
71+
prCyan("\nLinting process completed for total " + str(totalFeBeFileCount) + " javascript and ruby files.\n\n")
72+
73+
return
74+
runLinter()

0 commit comments

Comments
 (0)