Troubleshooting of Sonar issue: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
No edit summary
mNo edit summary
Line 1: Line 1:


{{Draft}}
{{Draft}}
== How to resolve "Add a new line at the end of this file." ==
Error message: Files should contain an empty newline at the end<ref>[https://gist.github.com/OleksiyRudenko/d51388345ea55767b7672307fe35adf3 Why should text files end with a newline?]</ref>
Solution:
* Add [[Return symbol | new line]] at the end of this file
Another solution:
* Add an new file {{kbd | key=add_newline_to_php_files.sh}} with the following content
<pre>
#!/bin/bash
# 檢查是否有傳入目錄參數
if [ "$#" -ne 1 ]; then
    echo "使用方法:./add_newline_to_php_files.sh [目錄路徑]"
    exit 1
fi
# 獲取目錄路徑參數
dir_path="$1"
# 遍歷指定目錄下的所有 .php 檔案
for file in "$dir_path"/*.php; do
    # 檢查檔案是否存在
    if [ -f "$file" ]; then
        # 讀取檔案的最後一行
        last_line=$(tail -n 1 "$file")
       
        # 檢查最後一行是否是空白行
        if [ "$last_line" != "" ]; then
            # 如果不是空白行,則添加一個換行符
            echo "" >> "$file"
        fi
    fi
done
</pre>
* Grant the execution permission {{kbd | key=chmod +x add_newline_to_php_files.sh}}
* Usage {{kbd | key=<nowiki>./add_newline_to_php_files.sh /path/to/php/directory_of_scripts</nowiki>}}


== How to resolve "Define and throw a dedicated exception instead of using a generic one" ==
== How to resolve "Define and throw a dedicated exception instead of using a generic one" ==
Anonymous user

Navigation menu