Skip to content

Commit

Permalink
refactor: prefer includes to determine if substrings exist
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Dec 15, 2024
1 parent 9f42f09 commit 79dae70
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/language-core/lib/codegen/script/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export function getTemplateUsageVars(options: ScriptCodegenOptions, ctx: ScriptC
}
}
for (const component of components) {
if (component.indexOf('.') >= 0) {
if (component.includes('.')) {
usageVars.add(component.split('.')[0]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/lib/plugins/file-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ const plugin: VueLanguagePlugin = ({ vueCompilerOptions }) => {
});
}
// ignore `<script src="...">`
else if (tag === 'script' && attrs.indexOf('src=') === -1) {
let type: 'script' | 'scriptSetup' = attrs.indexOf('type=') >= 0 ? 'scriptSetup' : 'script';
else if (tag === 'script' && !attrs.includes('src=')) {
let type: 'script' | 'scriptSetup' = attrs.includes('type=') ? 'scriptSetup' : 'script';
sfc.descriptor[type] = {
attrs: {},
content,
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/lib/ideFeatures/nameCasing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export async function detect(
}
for (const [tagName] of attrs) {
// attr-name
if (tagName.indexOf('-') >= 0) {
if (tagName.includes('-')) {
result.push(AttrNameCasing.Kebab);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function isCharacterTyping(document: TextDocument, change: { text: string
if (lastCharacter === undefined) { // delete text
return false;
}
if (change.text.indexOf('\n') >= 0) { // multi-line change
if (change.text.includes('\n')) { // multi-line change
return false;
}
return charReg.test(lastCharacter) && !charReg.test(nextCharacter);
Expand Down
4 changes: 2 additions & 2 deletions packages/language-service/lib/plugins/vue-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export function create(
while ((token = scanner.scan()) !== html.TokenType.EOS) {
if (token === html.TokenType.StartTag) {
const tagName = scanner.getTokenText();
const checkTag = tagName.indexOf('.') >= 0
const checkTag = tagName.includes('.')
? tagName
: components.find(component => component === tagName || hyphenateTag(component) === tagName);
if (checkTag) {
Expand All @@ -259,7 +259,7 @@ export function create(
}
else {
// remove modifiers
if (attrText.indexOf('.') >= 0) {
if (attrText.includes('.')) {
attrText = attrText.split('.')[0];
}
// normalize
Expand Down
6 changes: 3 additions & 3 deletions packages/typescript-plugin/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function getCompletionsAtPosition(vueOptions: VueCompilerOptions, getCompletions
if (result) {
// filter __VLS_
result.entries = result.entries.filter(
entry => entry.name.indexOf('__VLS_') === -1
&& (!entry.labelDetails?.description || entry.labelDetails.description.indexOf('__VLS_') === -1)
entry => !entry.name.includes('__VLS_')
&& !entry.labelDetails?.description?.includes('__VLS_')
);
// modify label
for (const item of result.entries) {
Expand Down Expand Up @@ -136,7 +136,7 @@ function getCodeFixesAtPosition(getCodeFixesAtPosition: ts.LanguageService['getC
return (...args) => {
let result = getCodeFixesAtPosition(...args);
// filter __VLS_
result = result.filter(entry => entry.description.indexOf('__VLS_') === -1);
result = result.filter(entry => !entry.description.includes('__VLS_'));
return result;
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-plugin/lib/requests/componentInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export function getComponentNames(
?.type
?.getProperties()
.map(c => c.name)
.filter(entry => entry.indexOf('$') === -1 && !entry.startsWith('_'))
.filter(entry => !entry.includes('$') && !entry.startsWith('_'))
?? [];
}

Expand All @@ -205,7 +205,7 @@ export function _getComponentNames(
?.type
?.getProperties()
.map(c => c.name)
.filter(entry => entry.indexOf('$') === -1 && !entry.startsWith('_'))
.filter(entry => !entry.includes('$') && !entry.startsWith('_'))
?? [];
}

Expand Down

0 comments on commit 79dae70

Please sign in to comment.