gpt4 book ai didi

SonarQube "Track lack of copyright and license headers"参数

转载 作者:行者123 更新时间:2023-12-01 04:50:45 42 4
gpt4 key购买 nike

SonarQube 有一个规则,允许您验证每个文件是否有版权和/或许可证。但是,我不确定如何使用可变年份指定版权。

例如,这是他们的合规解决方案:

/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

请求的参数是:
isRegularExpression 
Whether the headerFormat is a regular expression (Default Value: false)

.
headerFormat    
Expected copyright and license header

例如,如果“2008-2013”​​是一年,我将如何提供既允许 2015 年又允许 2016 年的格式?

最佳答案

我们的样式指南需要一个特定的 Java 源头文件:

/*
* [optional text] <CreationDate> [optional text]
* <Copyright (c) yyyy FOO-COMPANY. All Rights Reserved.>
*/

[] 括号表示它是可选的,<> 表示它必须存在,例如:

有效的
/*
* 03.05.2016
* Copyright (c) 2016 FOO-COMPANY. All Rights Reserved.
*/

也有效
/*
* just some text 03.05.2016 Fred Fart
* Copyright (c) 2016 FOO-COMPANY. All Rights Reserved.
*/

正则表达式确保日期有效,并且多个日期也是可能的,例如:
/*
* 23.09.2016
* Copyright (c) 2013-2016 FOO-COMPANY. All Rights Reserved.
*/

或者
/*
* 23.09.2016
* Copyright (c) 2013,2014,2016 FOO-COMPANY. All Rights Reserved.
*/

规则必须使用您的正则表达式配置为 headerFormatisRegularExpression=true我们的正则表达式配置如下:
^.+(?:0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[012])\.(19[7-9]\d|20[0-2]\d).+?Copyright \(c\) ((\b19[7-9]\d|20[0-2]\d)([,|-])?\b)* FOO-COMPANY\. All Rights Reserved\..+

关于SonarQube "Track lack of copyright and license headers"参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41265507/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com