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

コーディング規約スクリプトで,改行時の演算子が後置であることをチェックする #300

Open
meltingrabbit opened this issue Mar 22, 2022 · 2 comments
Assignees
Labels
Projects

Comments

@meltingrabbit
Copy link
Collaborator

概要

コーディング規約スクリプトで,改行時の演算子が後置であることをチェックする

close条件

チェックに入ってなかった

@meltingrabbit meltingrabbit added this to Backlog in C2A via automation Mar 22, 2022
@tarotene tarotene self-assigned this Apr 11, 2023
@tarotene
Copy link
Collaborator

tarotene commented Apr 11, 2023

def check_binary_operator_before_linebreak_(path: str, code_lines: list) -> bool:
    ptn = r'^\s*([+\-*/%]|<<|>>|<=|>=|==|!=|&{1,2}|\|{1,2}|\^)\s+'
    reptn = re.compile(ptn)
    for idx, line in enumerate(code_lines):
        if is_in_comment_context_in_multiline_(path, code_lines, idx):
            continue

        matched = reptn.match(line)
        if matched is None:
            continue

        print_err_(path, idx, f'LINE {idx} HAS STARTED WITH THE OPERATOR {matched.group(1)}.', line)
        return False

    return True

とりあえずこれで行頭が

  1. 任意個の空白文字
  2. +, -, *, /, %, <<, >>, <=, >=, ==, !=, &, |, &&, ||, ^
  3. 1個以上の空白文字

であるパターンははじけそう.改行時の演算子が前置であるパターンは原則として上記しかないはずで,試しに

  if (p_super->interface < 0
  || p_super->interface >= IF_LIST_MAX) return 

みたいなのを導入したらちゃんとそこだけエラーになった.

@tarotene
Copy link
Collaborator

tarotene commented Apr 11, 2023

Draft PR: #545

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
C2A
Backlog
Development

No branches or pull requests

2 participants