diff --git a/go.work b/go.work index 8dc91a631..56eb874d4 100644 --- a/go.work +++ b/go.work @@ -3,7 +3,6 @@ go 1.19 use ( . ./test/typecheck - ./tools/codescan ./tools/changelog ./tools/component ./tools/formitychecker diff --git a/scripts/verify-annotation-language.sh b/scripts/verify-annotation-language.sh deleted file mode 100755 index 6b863776c..000000000 --- a/scripts/verify-annotation-language.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env bash -# Copyright © 2023 OpenIM. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -# This script verifies whether codes follow golang convention. -# Usage: `scripts/verify-pkg-names.sh`. - -set -o errexit - -OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -source "${OPENIM_ROOT}/scripts/lib/init.sh" - -openim::golang::verify_go_version - -openim::golang::verify_go_version - -OPENIM_OUTPUT_HOSTBIN_TOOLS="${OPENIM_ROOT}/_output/bin/tools/linux/amd64" -CODESCAN_BINARY="${OPENIM_OUTPUT_HOSTBIN_TOOLS}/codescan" - -if [[ ! -f "${CODESCAN_BINARY}" ]]; then - echo "codescan binary not found, building..." - pushd "${OPENIM_ROOT}" >/dev/null - make build BINS="codescan" - popd >/dev/null -fi - -if [[ ! -f "${CODESCAN_BINARY}" ]]; then - echo "Failed to build codescan binary." - exit 1 -fi - -CONFIG_PATH="${OPENIM_ROOT}/tools/codescan/config.yaml" - -"${CODESCAN_BINARY}" -config "${CONFIG_PATH}" \ No newline at end of file diff --git a/tools/codescan/checker/checker.go b/tools/codescan/checker/checker.go deleted file mode 100644 index ad724dd5b..000000000 --- a/tools/codescan/checker/checker.go +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright © 2024 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package checker - -import ( - "bufio" - "fmt" - "os" - "path/filepath" - "regexp" - "strings" - - "github.com/openimsdk/open-im-server/tools/codescan/config" -) - -type CheckResult struct { - FilePath string - Lines []int -} - -func checkFileForChineseComments(filePath string) ([]CheckResult, error) { - file, err := os.Open(filePath) - if err != nil { - return nil, err - } - defer file.Close() - - var results []CheckResult - scanner := bufio.NewScanner(file) - reg := regexp.MustCompile(`[\p{Han}]+`) - lineNumber := 0 - - var linesWithChinese []int - for scanner.Scan() { - lineNumber++ - if reg.FindString(scanner.Text()) != "" { - linesWithChinese = append(linesWithChinese, lineNumber) - } - } - - if len(linesWithChinese) > 0 { - results = append(results, CheckResult{ - FilePath: filePath, - Lines: linesWithChinese, - }) - } - - if err := scanner.Err(); err != nil { - return nil, err - } - - return results, nil -} - -func WalkDirAndCheckComments(cfg config.Config) error { - var allResults []CheckResult - err := filepath.Walk(cfg.Directory, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if info.IsDir() { - return nil - } - for _, fileType := range cfg.FileTypes { - if filepath.Ext(path) == fileType { - results, err := checkFileForChineseComments(path) - if err != nil { - return err - } - if len(results) > 0 { - allResults = append(allResults, results...) - } - } - } - return nil - }) - - if err != nil { - return err - } - - if len(allResults) > 0 { - var errMsg strings.Builder - errMsg.WriteString("Files containing Chinese comments:\n") - for _, result := range allResults { - errMsg.WriteString(fmt.Sprintf("%s: Lines %v\n", result.FilePath, result.Lines)) - } - return fmt.Errorf(errMsg.String()) - } - - return nil -} diff --git a/tools/codescan/codescan.go b/tools/codescan/codescan.go deleted file mode 100644 index a83e895fc..000000000 --- a/tools/codescan/codescan.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright © 2024 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -import ( - "log" - - "github.com/openimsdk/open-im-server/tools/codescan/checker" - "github.com/openimsdk/open-im-server/tools/codescan/config" -) - -func main() { - cfg, err := config.ParseConfig() - if err != nil { - log.Fatalf("Error parsing config: %v", err) - } - - err = checker.WalkDirAndCheckComments(cfg) - if err != nil { - panic(err) - } -} diff --git a/tools/codescan/config.yaml b/tools/codescan/config.yaml deleted file mode 100644 index 32a8c1f54..000000000 --- a/tools/codescan/config.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright © 2024 OpenIM. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -directory: ./ -file_types: - - .go - - .yaml - - .yml -languages: - - Chinese \ No newline at end of file diff --git a/tools/codescan/config/config.go b/tools/codescan/config/config.go deleted file mode 100644 index aebf0d4f7..000000000 --- a/tools/codescan/config/config.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright © 2024 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -import ( - "flag" - "log" - "os" - - "gopkg.in/yaml.v2" -) - -type Config struct { - Directory string `yaml:"directory"` - FileTypes []string `yaml:"file_types"` - Languages []string `yaml:"languages"` -} - -func ParseConfig() (Config, error) { - var configPath string - flag.StringVar(&configPath, "config", "./", "Path to config file") - flag.Parse() - - var config Config - if configPath != "" { - configFile, err := os.ReadFile(configPath) - if err != nil { - return Config{}, err - } - if err := yaml.Unmarshal(configFile, &config); err != nil { - return Config{}, err - } - } else { - log.Fatal("Config file must be provided") - } - return config, nil -} diff --git a/tools/codescan/go.mod b/tools/codescan/go.mod deleted file mode 100644 index 2ad132101..000000000 --- a/tools/codescan/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/openimsdk/open-im-server/tools/codescan - -go 1.19