|
1 |
| -# Development of a Go-Based Conformity Checker for Project File and Directory Naming Standards |
| 1 | +# README for Standardizer |
2 | 2 |
|
3 |
| -An Github Actions Tools, Development of a Go-Based Conformity Checker for Project File and Directory Naming Standards |
| 3 | +## Overview |
4 | 4 |
|
5 |
| -### 1. Project Overview |
| 5 | +**Standardizer** is a versatile GitHub Action tool designed to ensure your project's file and directory names adhere to specified naming conventions. It automates the process of checking the conformity of naming standards within your repository, saving time and maintaining consistency across your codebase. Standardizer can be easily integrated into your GitHub workflows or used locally to inspect your project's structure for any deviations from the defined naming rules. |
6 | 6 |
|
7 |
| -#### Project Name |
| 7 | +## Features |
8 | 8 |
|
9 |
| -- `GoConstandardizer` |
| 9 | +- **Flexible Configuration**: Customize naming rules for files and directories through a straightforward YAML configuration. |
| 10 | +- **Regex Support for Ignoring Formats**: Utilize regular expressions to define exceptions for file formats that do not require standardization. |
| 11 | +- **Environment Variables & Flags Support**: Specify the configuration file's location using environment variables or command-line flags for versatile setup options. |
| 12 | +- **Local & CI Integration**: Designed for both local development environments and continuous integration workflows, ensuring consistency across different stages of development. |
10 | 13 |
|
11 |
| -#### Functionality Description |
| 14 | +## Getting Started |
12 | 15 |
|
13 |
| -- Checks if the file and subdirectory names in a specified directory adhere to specific naming conventions. |
14 |
| -- Supports specific file types (e.g., `.go`, `.yml`, `.yaml`, `.md`, `.sh`, etc.). |
15 |
| -- Allows users to specify directories to be checked and directories to be ignored. |
16 |
| -- More read https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/code-conventions.md |
| 16 | +### Installation |
17 | 17 |
|
18 |
| -#### Naming Conventions |
| 18 | +For local use, you can either download the latest release from [GitHub Releases](https://github.com/kubecub/standardizer/releases/) or install directly using Go: |
19 | 19 |
|
20 |
| -- Go files: Only underscores are allowed. |
21 |
| -- YAML, YML, and Markdown files: Only hyphens are allowed. |
22 |
| -- Directories: Only underscores are allowed. |
23 |
| - |
24 |
| -### 2. File Structure |
25 |
| - |
26 |
| -- `main.go`: Entry point of the program, handles command-line arguments. |
27 |
| -- `checker/checker.go`: Contains the core logic. |
28 |
| -- `config/config.go`: Parses and stores configuration information. |
29 |
| - |
30 |
| -### 3. Core Code Design |
31 |
| - |
32 |
| -#### main.go |
33 |
| - |
34 |
| -- Parses command-line arguments, including the directory to be checked and directories to be ignored. |
35 |
| -- Calls the `checker` module for checking. |
36 |
| - |
37 |
| -#### config.go |
| 20 | +```shell |
| 21 | +go install github.com/kubecub/standardizer@latest |
| 22 | +``` |
38 | 23 |
|
39 |
| -- Defines a configuration structure, such as directories to check and ignore. |
| 24 | +### Configuration |
| 25 | + |
| 26 | +Create a `standardizer.yml` configuration file in your project's root directory or under `.github/`. Alternatively, specify the configuration file's path through environment variables or flags. |
| 27 | + |
| 28 | +**Example `standardizer.yml` Configuration:** |
| 29 | + |
| 30 | +```yaml |
| 31 | +baseConfig: |
| 32 | + searchDirectory: "./" |
| 33 | + ignoreCase: false |
| 34 | + |
| 35 | +directoryNaming: |
| 36 | + allowHyphens: true |
| 37 | + allowUnderscores: false |
| 38 | + mustBeLowercase: true |
| 39 | + |
| 40 | +fileNaming: |
| 41 | + allowHyphens: true |
| 42 | + allowUnderscores: true |
| 43 | + mustBeLowercase: true |
| 44 | + |
| 45 | +ignoreFormats: |
| 46 | + - "\\.log$" |
| 47 | + - "\\.env$" |
| 48 | + - "README\\.md$" |
| 49 | + - "_test\\.go$" |
| 50 | + - "\\.md$" |
| 51 | + - LICENSE |
| 52 | + |
| 53 | +ignoreDirectories: |
| 54 | + - "vendor" |
| 55 | + - ".git" |
| 56 | + - "node_modules" |
| 57 | + - "logs" |
| 58 | + - "CHANGELOG" |
| 59 | + - "components" |
| 60 | + - "_output" |
| 61 | + - "tools/openim-web" |
| 62 | + - "CHANGELOG" |
| 63 | + - "examples/Test_directory" |
| 64 | + |
| 65 | +fileTypeSpecificNaming: |
| 66 | + ".yaml": |
| 67 | + allowHyphens: true |
| 68 | + allowUnderscores: false |
| 69 | + mustBeLowercase: true |
| 70 | + ".go": |
| 71 | + allowHyphens: false |
| 72 | + allowUnderscores: true |
| 73 | + mustBeLowercase: true |
| 74 | +``` |
40 | 75 |
|
41 |
| -#### checker.go |
| 76 | +### Configuration Details |
42 | 77 |
|
43 |
| -- Iterates through the specified directory. |
44 |
| -- Applies different naming rules based on file types and directory names. |
45 |
| -- Records files or directories that do not conform to the standards. |
| 78 | +- **baseConfig**: General settings for the scan, such as the directory to search (`searchDirectory`) and whether to ignore case sensitivity (`ignoreCase`). |
| 79 | +- **directoryNaming** & **fileNaming**: Define the allowed naming conventions for directories and files, respectively, including the use of hyphens, underscores, and case sensitivity. |
| 80 | +- **ignoreFormats**: A list of regex patterns for file formats that should be ignored during the naming checks. This is useful for excluding specific file types or naming patterns. |
| 81 | +- **ignoreDirectories**: Directories to exclude from the scan, ensuring that vendor or third-party directories won't affect your compliance results. |
| 82 | +- **fileTypeSpecificNaming**: Allows for specifying naming conventions on a per-file-extension basis, offering greater flexibility for projects that use a variety of file types with different standards. |
46 | 83 |
|
47 |
| -### 4. Pseudocode Example |
| 84 | +### Using Standardizer in GitHub Actions |
48 | 85 |
|
49 |
| -#### main.go |
| 86 | +To integrate Standardizer into your GitHub Actions workflow, add the following step to your `.github/workflows/main.yml`: |
50 | 87 |
|
51 |
| -```go |
52 |
| -package main |
| 88 | +```yaml |
| 89 | +- name: Conformity Checker for Project |
| 90 | + uses: kubecub/standardizer@main # or use a specific tag like @v1.0.0 |
| 91 | +``` |
53 | 92 |
|
54 |
| -import ( |
55 |
| - "flag" |
56 |
| - "fmt" |
57 |
| - "GoConstandardizer/checker" |
58 |
| -) |
| 93 | +### Local Usage |
59 | 94 |
|
60 |
| -func main() { |
61 |
| - // Parse command-line arguments |
62 |
| - var targetDir string |
63 |
| - var ignoreDirs string |
64 |
| - flag.StringVar(&targetDir, "target", ".", "Directory to check") |
65 |
| - flag.StringVar(&ignoreDirs, "ignore", "", "Directories to ignore") |
66 |
| - flag.Parse() |
| 95 | +After configuring `standardizer.yml`, run Standardizer locally to check your project's naming conventions: |
67 | 96 |
|
68 |
| - // Call the checker |
69 |
| - err := checker.CheckDirectory(targetDir, ignoreDirs) |
70 |
| - if err != nil { |
71 |
| - fmt.Println("Error:", err) |
72 |
| - } |
73 |
| -} |
| 97 | +```shell |
| 98 | +standardizer -config .github/standardizer.yml |
74 | 99 | ```
|
75 | 100 |
|
76 |
| -#### checker.go |
77 |
| - |
78 |
| -```go |
79 |
| -package checker |
| 101 | +### Success Output |
80 | 102 |
|
81 |
| -import ( |
82 |
| - // Import necessary packages |
83 |
| -) |
| 103 | +A successful run will output the number of directories and files checked, along with any identified issues: |
84 | 104 |
|
85 |
| -func CheckDirectory(targetDir, ignoreDirs string) error { |
86 |
| - // Iterate through the directory, applying rules to check file and directory names |
87 |
| - // Return any found errors or non-conformities |
88 |
| - return nil |
| 105 | +```json |
| 106 | +{ |
| 107 | + "CheckedDirectories": 4, |
| 108 | + "CheckedFiles": 15, |
| 109 | + "Issues": null |
89 | 110 | }
|
90 | 111 | ```
|
91 | 112 |
|
92 |
| -### 5. Implementation Details |
| 113 | +- **CheckedDirectories** & **CheckedFiles**: The count of directories and files that were checked. |
| 114 | +- **Issues**: Lists any naming convention violations found. `null` indicates no issues were detected. |
93 | 115 |
|
94 |
| -- **File and Directory Traversal**: Use Go's `path/filepath` package to traverse directories and subdirectories. |
95 |
| -- **Naming Rules Checking**: Apply different regex expressions for naming checks based on file extensions. |
96 |
| -- **Error Handling and Reporting**: Record files or directories that do not conform and report to the user. |
| 116 | +## Contributing |
97 | 117 |
|
98 |
| -### 6. Future Development and Extensions |
| 118 | +Contributions to Standardizer are welcome! Please refer to the project's GitHub page for contribution guidelines: [https://github.com/kubecub/standardizer](https://github.com/kubecub/standardizer). |
99 | 119 |
|
100 |
| -- Support more file types and naming rules. |
101 |
| -- Provide more detailed error reports, such as showing line numbers and specific naming mistakes. |
102 |
| -- Add a graphical or web interface for non-command-line users. |
| 120 | +## License |
103 | 121 |
|
104 |
| -The above is an overview of the entire project's design. Following this design, specific coding implementation can begin. Note that the actual implementation may need adjustments based on real-world conditions. |
| 122 | +Standardizer is released under the MIT License. See the LICENSE file for more details. |
0 commit comments