Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@
enabled = false
}

tasks.register("updateLicenses") {

Check warning on line 451 in build.gradle.kts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define group and description for this task

See more on https://sonarcloud.io/project/issues?id=1c-syntax_bsl-language-server&issues=AZraFUpAPn89tq2rh7Fp&open=AZraFUpAPn89tq2rh7Fp&pullRequest=3630
dependsOn(tasks.licenseFormat)
}

fun buildTime(): String {
val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
formatter.timeZone = TimeZone.getTimeZone("UTC")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import lombok.extern.slf4j.Slf4j;
import org.antlr.v4.runtime.Token;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.WordUtils;
import org.languagetool.JLanguageTool;
import org.languagetool.Languages;
import org.languagetool.rules.RuleMatch;
Expand All @@ -48,7 +49,9 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
Expand Down Expand Up @@ -107,20 +110,39 @@
)
private String userWordsToIgnore = DEFAULT_USER_WORDS_TO_IGNORE;

/**
* Готовый список слов для игнорирования
*/
private Set<String> wordsToIgnore = new HashSet<>();

@DiagnosticParameter(
type = Boolean.class
)
private Boolean caseInsensitive = false;

@Override
public void configure(Map<String, Object> configuration) {
super.configure(configuration);
minWordLength = Math.max(minWordLength, DEFAULT_MIN_WORD_LENGTH);
wordsToIgnore = makeWordsToIgnore();
}

private Set<String> getWordsToIgnore() {
var delimiter = ",";
String exceptions = SPACES_PATTERN.matcher(info.getResourceString("diagnosticExceptions")).replaceAll("");
private Set<String> makeWordsToIgnore() {
char delimiter = ',';

Check warning on line 131 in src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Declare this local variable with "var" instead.

See more on https://sonarcloud.io/project/issues?id=1c-syntax_bsl-language-server&issues=AZraFUm1Pn89tq2rh7Fo&open=AZraFUm1Pn89tq2rh7Fo&pullRequest=3630
var exceptions = SPACES_PATTERN.matcher(info.getResourceString("diagnosticExceptions")).replaceAll("");
if (!userWordsToIgnore.isEmpty()) {
exceptions = exceptions + delimiter + SPACES_PATTERN.matcher(userWordsToIgnore).replaceAll("");
exceptions += delimiter + SPACES_PATTERN.matcher(userWordsToIgnore).replaceAll("");
}

// добавим к переданным строки в разных регистрах
if (caseInsensitive && !exceptions.isEmpty()) {

Check warning on line 138 in src/main/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/TypoDiagnostic.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a primitive boolean expression here.

See more on https://sonarcloud.io/project/issues?id=1c-syntax_bsl-language-server&issues=AZraFUm1Pn89tq2rh7Fn&open=AZraFUm1Pn89tq2rh7Fn&pullRequest=3630
exceptions +=
delimiter + exceptions.toLowerCase(Locale.getDefault()) // верхний регистр
+ delimiter + exceptions.toUpperCase(Locale.getDefault()) // нижний регистр
+ delimiter + WordUtils.capitalizeFully(exceptions, delimiter); // титульный
}

return Arrays.stream(exceptions.split(delimiter))
return Arrays.stream(exceptions.split(String.valueOf(delimiter)))
.collect(Collectors.toSet());
}

Expand All @@ -135,7 +157,6 @@
private Map<String, List<Token>> getTokensMap(
DocumentContext documentContext
) {
Set<String> wordsToIgnore = getWordsToIgnore();
Map<String, List<Token>> tokensMap = new HashMap<>();

Trees.findAllRuleNodes(documentContext.getAst(), rulesToFind).stream()
Expand All @@ -144,9 +165,9 @@
.filter(token -> !FORMAT_STRING_PATTERN.matcher(token.getText()).find())
.forEach((Token token) -> {
String curText = QUOTE_PATTERN.matcher(token.getText()).replaceAll("").trim();
String[] camelCaseSplitedWords = StringUtils.splitByCharacterTypeCamelCase(curText);
String[] camelCaseSplitWords = StringUtils.splitByCharacterTypeCamelCase(curText);

Arrays.stream(camelCaseSplitedWords)
Arrays.stream(camelCaseSplitWords)
.filter(Predicate.not(String::isBlank))
.filter(element -> element.length() >= minWordLength)
.filter(Predicate.not(wordsToIgnore::contains))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,12 @@
"default": 3,
"type": "integer",
"title": "Minimum length for checked words"
},
"caseInsensitive": {
"description": "Excluded words are case-insensitive",
"default": false,
"type": "boolean",
"title": "Excluded words are case-insensitive"
}
},
"$id": "#/definitions/Typo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,15 +924,30 @@
"properties": {
"type": {
"type": "string",
"enum": ["ERROR", "CODE_SMELL", "VULNERABILITY", "SECURITY_HOTSPOT"]
"enum": [
"ERROR",
"CODE_SMELL",
"VULNERABILITY",
"SECURITY_HOTSPOT"
]
},
"severity": {
"type": "string",
"enum": ["INFO", "MINOR", "MAJOR", "CRITICAL", "BLOCKER"]
"enum": [
"INFO",
"MINOR",
"MAJOR",
"CRITICAL",
"BLOCKER"
]
},
"scope": {
"type": "string",
"enum": ["ALL", "BSL", "OS"]
"enum": [
"ALL",
"BSL",
"OS"
]
},
"modules": {
"type": "array",
Expand Down Expand Up @@ -963,7 +978,12 @@
},
"lspSeverity": {
"type": "string",
"enum": ["Error", "Warning", "Information", "Hint"],
"enum": [
"Error",
"Warning",
"Information",
"Hint"
],
"description": "LSP severity level (Error, Warning, Information, Hint). If not specified, calculated automatically based on type and severity."
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ diagnosticExceptions=Str,Autotest,Infobase,Enums,Len,Desc,Asc,Overridable,GUID,E
Sys,Saas,www,yyyy,xsl,src,deserialization,Params,Archiver,Serializer,xsi,ico,epf,cfu,txt,htm,rtf,ppt,vsd,mpp,mdb,msg,rar,exe,grs,geo,jpg,bmp,\
tif,gif,png,pdf,odt,odf,odp,odg,ods,erf,docx,xlsx,pptx,utf,xsd,SRVR,saas,wsdl,Apdex,APDEX,uid,XLS,XLSX,html,TXT,ODT,Addin,DIB
minWordLength=Minimum length for checked words
userWordsToIgnore=Dictionary for excluding words (comma separated)
userWordsToIgnore=Dictionary for excluding words (comma separated)
caseInsensitive=Excluded words are case-insensitive
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ diagnosticExceptions=Автогенерируемых,Автогруппиров
,Студотряде,Субконто,Таб,Техподдержки,Токене,Транслите,Тэги,Тэгов,Убыв,Физлица,Финализировать,Фич,Хэш,Штрихкодам\
,Штрихкодом,Штрихкоду,Мдд,Чммсс
minWordLength=Минимальная длина проверяемых слов
userWordsToIgnore=Пользовательский словарь исключений (через запятую)
userWordsToIgnore=Пользовательский словарь исключений (через запятую)
caseInsensitive=Не учитывать регистр в словаре исключений
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ void testConfigureUserWordsToIgnore() {
.hasRange(8, 13, 8, 18);
}

@Test
void testConfigureUserWordsToIgnoreCaseInsensitive() {

Map<String, Object> configuration = diagnosticInstance.getInfo().getDefaultConfiguration();
configuration.put("userWordsToIgnore", "ваРинаты");
configuration.put("caseInsensitive", true);
diagnosticInstance.configure(configuration);

List<Diagnostic> diagnostics = getDiagnostics();

assertThat(diagnostics).hasSize(2);
assertThat(diagnostics, true)
.hasRange(1, 13, 1, 21)
.hasRange(8, 13, 8, 18);
}

@Test
void testConfigureUserWordsToIgnoreWithSpaces() {

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/diagnostics/TypoDiagnostic.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
Возврат;
Сообщить("ыть"); // срабатывание здесь
ДеньНедели = Формат(ДатаКолонки, "ДФ=ддд"); // Нет срабатывания. Форматная строка
ЗапроситьДанныеОКВЭДФССВТранзакции = Истина; // Нет срабатывания. Аббревиатура
КонецФункции
Loading