forked from hyperledger-bevel/bevel
-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (129 loc) · 5.81 KB
/
spellcheck.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
---
name: spell and grammer check
on:
push:
branches:
- "**"
pull_request:
paths:
- 'docs/**'
types: [opened, edited, updated]
env:
SPELL_CHECK_DISABLED: false
GRAMMAR_CHECK_DISABLED: false
jobs:
check-spelling-and-grammar:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
# Install the dependencies for grammer check and spell check.
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
python -m pip install pyspelling
sudo apt-get install hunspell hunspell-en-us aspell aspell-en
pip install --user --upgrade language_tool_python
- uses: actions/checkout@v2
- name: Spellcheck
if: ${{ env.SPELL_CHECK_DISABLED == 'false' }}
uses: rojopolis/[email protected]
with:
config_path: .github/.spellcheck.yaml
source_files: "docs**/*.md" # name of the file to check spell
task_name: Markdown
# To check the grammatical mistakes of the given files and folders.
- name: Run grammar check
if: ${{ env.GRAMMAR_CHECK_DISABLED == 'false' }}
run: |
python - <<EOF
import language_tool_python
# Initialize LanguageTool
tool = language_tool_python.LanguageTool('en-US') # You can specify the language you want to check.
# Specify the directory path
directory_path = 'docs'
# Read the text from your file
file_path = 'docs**/*.md' # Update the path accordingly
with open(file_path, 'r', encoding='utf-8') as file:
text = file.read()
# Check for grammar errors
matches = tool.check(text)
# Print relevant grammar errors with line numbers
relevant_errors = []
if matches:
for match in matches:
if match.ruleId == 'MORFOLOGIK_RULE_EN_US':
line_number = text.count('\n', 0, match.offset) + 1
relevant_errors.append((line_number, match.message))
if relevant_errors:
for error in relevant_errors:
line_number, message = error
print(f"Grammar error at line {line_number}: {message}")
exit(1)
else:
print("No grammar errors found.")
exit(0)
EOF
# # Print grammar errors with line numbers
# if matches:
# for match in matches:
# line_number = text.count('\n', 0, match.offset) + 1
# print(f"Grammar error at line {line_number}: {match.message}")
# # Correct the grammar error
# corrected_text = language_tool_python.correct(text, matches)
# # Write the corrected text back to the file
# with open(file_path, 'w', encoding='utf-8') as file:
# file.write(corrected_text)
# print("Grammar errors corrected successfully.")
# else:
# print("No grammar errors found.")
# EOF
# # Print grammar errors with line numbers
# if matches:
# for match in matches:
# print("Match context:", match.context) # Add this line for debugging
# if match.context and 'offset' in match.context[0]:
# line_range = match.context[0]['offset']
# start_line = text.count('\n', 0, int(line_range)) + 1
# end_line = text.count('\n', int(line_range), int(line_range) + match.context[0]['length']) + 1
# print(f"Grammar error from line {start_line} to {end_line}: {match.message}")
# else:
# print("Unexpected match context structure:", match.context) # Add this line for debugging
# # Handle the case when the match context doesn't have the expected structure
# else:
# # No grammar errors found, print a success message
# print("No grammar errors found.")
# EOF
# # # Specify the directory path
# # directory_path = '.github/checking.txt'
# # Iterate through all files in the directory
# for filename in os.listdir(directory_path):
# file_path = os.path.join(directory_path, filename)
# if os.path.isfile(file_path):
# # Read the text from your file
# # file_path = '.github/checking.txt' # Update the path accordingly
# with open(file_path, 'r', encoding='utf-8') as file:
# text = file.read()
# # Check for grammar errors
# matches = tool.check(text)
# # Print grammar errors with line numbers
# if matches:
# for match in matches:
# print(f"File: {filename}")
# line_range = match.context[0]['offset']
# start_line = text.count('\n', 0, int(line_range)) + 1
# end_line = text.count('\n', int(line_range), int(line_range) + match.context[0]['length']) + 1
# print(f"Grammar error from line {start_line} to {end_line}: {match.message}")
# else:
# print(f"No grammar errors found in {filename}")
# # # # Exit with a non-zero code to indicate failure
# # # exit(1)
# print(f"No grammar errors found in {filename}")
# # else:
# # # No grammar errors found, print a success message
# # print("No grammar errors found.")
# # exit(0)
# EOF