Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for detecting bad characters. #27315

Merged
merged 1 commit into from
May 10, 2021

Conversation

s-kawamura-w664
Copy link
Contributor

This is script that find control-code(0x00-0x1f) in text files.
I could find them in several files. Please look at PR #26965, #27173, #27171.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 30, 2021
@k8s-ci-robot k8s-ci-robot added the sig/docs Categorizes an issue or PR as relevant to SIG Docs. label Mar 30, 2021
@netlify
Copy link

netlify bot commented Mar 30, 2021

Deploy preview for kubernetes-io-master-staging ready!

Built with commit 7fde042

https://deploy-preview-27315--kubernetes-io-master-staging.netlify.app

Copy link
Contributor

@sftim sftim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea

We could run this as a CI test, in fact.

@s-ito-ts
Copy link
Contributor

s-ito-ts commented Apr 1, 2021

Could you add how to use this script to the README?
https://github.com/kubernetes/website/blob/master/scripts/README.md

@oomichi
Copy link
Member

oomichi commented Apr 1, 2021

We could run this as a CI test, in fact.

@sftim That is a nice idea.
Do you know how to enable some script on CI test of this website repo?
On kubernetes/kubernetes repo, hack/verify-***.sh files are distinguished as CI testing scripts and these scripts are automatically operated. But I could not find such way on this repo.

/cc @oomichi

@s-kawamura-w664
Copy link
Contributor Author

@s-ito-ts
I updated README.md.
Could you please review?

Could you add how to use this script to the README?
https://github.com/kubernetes/website/blob/master/scripts/README.md

Copy link
Member

@oomichi oomichi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments to make the code more readable.


def check_dir(path, ext):
for f in os.listdir(path):
if(f[0] != "."):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reduce nests, here can be

if(f[0] == "."):
    continue
fullpath = os.path.join(path, f)
...

fullpath = os.path.join(path, f)
if(os.path.isfile(fullpath)):
exts = os.path.splitext(f)
if(exts[1] == ext):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto:

if(exts[1] != ext):
    continue
check_ctrlcode(fullpath)

with open(filepath, encoding='utf-8') as f:
while True:
str = f.readline()
if str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto:

if str == "":
    break
line = line + 1
# check 0x00-0x1f except 0x09(HT), 0x0a(LF), 0x0d(CR)
...

# check 0x00-0x1f except 0x09(HT), 0x0a(LF), 0x0d(CR)
pattern = re.compile('[\u0000-\u0008\u000b\u000c\u000e-\u001f]')
m = pattern.search(str)
if(m != None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto:

if(m == None):
    continue
pos = m.end()
ctrl = m.group().encode("utf-8")
...

@s-kawamura-w664
Copy link
Contributor Author

some comments to make the code more readable.

@oomichi
I fixed them according to your review comment.
Could you please review my fixes?

Copy link
Member

@oomichi oomichi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating.
Most part seems good for me, just one comment.

continue
check_ctrlcode(fullpath)
else:
check_dir(fullpath, ext)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar point. How about changing line 30-34 to

if(os.path.isdir(fullpath)):
    check_dir(fullpath, ext)
    continue
exts = os.path.splitext(f)
if(exts[1] != ext):
    continue
check_ctrlcode(fullpath)

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think nest is a problem.
I thought about the ease of understanding the conditions.
My code feels easy to understand the if-else condition.
Your code feels easy to understand as a loop condition.
I would like to accept your proposal and fix it.
After fixed, I'll request you to review.

Copy link
Member

@oomichi oomichi Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This point is not only for nest.
This point makes condition same as the next called function.
In my suggestion, isdir() condition calls check_dir().
I think that is pretty straightforward and easy to understand what is the purpose here.

Co-authored-by: Shu Muto <shu.mutow@nec.com>
@s-kawamura-w664
Copy link
Contributor Author

Thanks for updating.
Most part seems good for me, just one comment.

@oomichi
Thanks for your comment.
I fixed it.
Could you please review my fixes?

Copy link
Member

@oomichi oomichi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 8, 2021
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 73d9393f4624ed62b81eb568c45ad201cf84c7a2

@s-kawamura-w664
Copy link
Contributor Author

/assign @steveperry-53

Could you please review?
If this is OK, please approve.

Copy link
Member

@savitharaghunathan savitharaghunathan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: savitharaghunathan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 10, 2021
@k8s-ci-robot k8s-ci-robot merged commit 448df54 into kubernetes:master May 10, 2021
@s-kawamura-w664 s-kawamura-w664 deleted the patch-script branch October 19, 2022 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants