Vue CLI ESLint adds extra space to multiline blocks

Working on a project set up with the VUE CLI and default settings in VSCode, I'm struggling with formatting a list at the end of a string.

If I use this code:

<span v-if="fruits">(<span v-for="(fruit,index) in fruits" :key="index">{{fruit}}<span v-if="index != (fruits.length - 1)">, </span></span>)

I get the desired output: (orange, banana, strawberry).

However, when I format the code using ESLint, it changes to:

<span v-if="fruits">
  (
  <span v-for="(fruit,index) in fruits" :key="index">
    {{fruit}}
    <span v-if="index != (fruits.length - 1)">, </span>
  </span>)
</span>

Although this formatting is more readable, it introduces unwanted spaces resulting in ( orange , banana , strawberry ).

Is there a way to remove these extra spaces without disabling ESLint?

As a newcomer to web development, I've come across similar issues but most solutions involve adjusting CSS margins rather than deleting the spaces directly.

I initially tried using the .join method in JavaScript, but realized I would need individual spans for each fruit to apply specific CSS classes.

Answer №1

If you want to keep your whitespace intact, consider switching to the Prettier formatter. However, be aware that it may result in a messy code like this:

  <span v-if="fruit"
    >(<span v-for="(fruit, index) in fruit" :key="index"
      >{{ fruit }}<span v-if="index != fruit.length - 1">, </span></span
    >)</span
  >

Alternatively, you can bypass the formatting rules by ignoring the single-line loop:

<!-- eslint-ignore-next-line -->
<span v-if="fruits">(<span v-for="(fruit,index) in fruits" :key="index">{{fruit}}<span v-if="index != (fruits.length - 1)">, </span></span>)</span>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

If I do not utilize v-model within computed, then computed will not provide a value

I'm fairly new to coding in JS and Vue.js. I've been attempting to create a dynamic search input feature that filters an array of objects fetched from my API based on user input. The strange issue I'm coming across is that the computed metho ...

Utilizing Django for tables with over two items in a template

I've been on the lookout for a solution to create a Django template that can display more than just 2 values per row in a table. Imagine having a class with 5 attributes, and wanting these attribute values showcased in a table on your HTML page. Init ...

What is the best way to split CSS into multiple files for a single page application?

I have a project in Angular Kendo where I am working on developing a single page application. The plan is to separate the business logic into different pages, each with its own set of JavaScript, CSS, and HTML files that are dynamically loaded based on use ...

Styling with CSS in a React component

I am trying to display a row of buttons instead of columns on my webpage. I have used display:flex but it is still showing as a column. What I want is for each button to display the first character of its name underneath it, with all buttons lined up next ...

What is the process for sending a POST request from a plain JavaScript application?

I've developed a stand-alone webpage named index.html that includes a basic form with an input field. Every time I attempt to submit the form by clicking the button, I intend to send a POST request to my server. Unfortunately, the browser keeps displa ...

What makes the vue <template> is incorrect when using v-bind:src?

I'm facing a challenge in dynamically switching html content. I tried using vue-loader src to import, but v-bind:src doesn't seem to have any effect. <template src="./app.html"></template> It seems to be working fine here. <temp ...

Unable to implement CSS styling on Bootstrap collapsible menu

When you visit this website and resize the browser window to reveal the toggle buttons, clicking on either one will only expand the dropdowns to a small portion of the screen width. I would like both dropdowns to stretch out and fill 100% of the available ...

Linking a script to a button in ASP .NET MVC Razor View

I'm struggling to get a button to invoke a script. Here's the button and script: <script> function SubmitClick () { var pid = $(this).data('personid'); var sid = $(this).data('surveyid'); v ...

Retrieve the precise input entered by the user in a text box

Currently, I am facing an issue with a textarea where the value inputted by the user is being displayed in a chatbox-like manner. However, there is a specific requirement where if a user types "/command hello", only "hello" should be displayed without the ...

various types of font colors within the text box

If I have a text box with the content "eg. 'one'" Can I set the font color of "eg." to color:black and "'one'" to color:red? Below is the HTML code: <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" Text="eg.-one"> ...

Create a Bootstrap Affix that sticks the header at the top of the page after scrolling 100

Currently, I am implementing Bootstrap Affix on my header with the intention of making it fixed after scrolling 100px down the page. Here is the jQuery code snippet I have incorporated: $('#navbar').affix({ offset: { top: 100, ...

Chrome browser rendering image as PHP/CSS/HTML web navigation bar

I've hit a snag while working on my small website. The navigation of the website is functioning properly in Internet Explorer, but in Google Chrome, it's not clickable. Initially, I thought the issue might be related to the background image of ...

Ensuring Accessibility in Vue using Jest-Axe: It is important for buttons to have clear and distinguishable text. Is there a way to include a button name or aria-label when the content is passed through a slot

I have been focusing on enhancing the accessibility of my project by incorporating ESLint rules from vuejs-accessibility and integrating Jest-Axe. During the accessibility tests for my button components, Jest-Axe highlighted that Buttons must have discern ...

Customizing the WordPress dashboard logo for a multisite platform

As the superadmin of a smaller network of multisites for a client, I am faced with the challenge of organizing sites that all have the same name. This has created quite a cluttered mess: https://i.sstatic.net/qFWwq.png Unfortunately, changing the titles ...

How can I make an HTML button function with a JavaScript script?

When I click a button in an HTML file, it should trigger a function in a JavaScript file to display an alert that says "hey." However, this simple task is not working for me and I am unsure why. Java Script is enabled in my browser (Google Chrome) and I am ...

A guide to retrieving all image URLs when a checkbox is selected using Javascript

My goal is to extract only image URLs from the concatenated values of price and picture URL. However, when I check different images using checkboxes, it always displays the URL of the first selected image. When I try to split the value, all the prices and ...

Incorporate a 'back' button in the tab content of vue-form-wizard

Currently, I'm working on implementing a vue form wizard from the repository: https://github.com/BinarCode/vue-form-wizard My challenge is to include a button in the second tab-content itself instead of having it placed in the footer. I attempted th ...

Identifying Browsers using CSS

I am struggling to understand why my HTML5 website appears differently in each browser. It seems like a CSS issue, but I can't pinpoint the exact problem. Here are screenshots of how the site looks on different browsers: Chrome: Safari: Internet E ...

What is the best method for deleting an uploaded image from a box?

My code is quite lengthy, so I'll just showcase the JavaScript portion here. Here is a snippet of my JavaScript code: <script type="text/javascript"> let current = 0; for(let i = 0; i < 5; i++) { $('#thumbnail-view- ...

Whenever I save innerHTML to a text file, a newline break is automatically inserted in the saved text file. The same newline break also appears when I reload the page

Whenever the button is clicked, the text file saves with a line break for every p tag inside div1, not just the first one. <p>x1</p> ....linebreak If the button is clicked three times, reloaded, and then clicked again, the result is as follows ...