[go: nahoru, domu]

Skip to content

JulianCataldo/eslint-plugin-playground

Repository files navigation

ESLint Plugin Playground

Experiment for making ESLint Stylistic to format like Prettier does for html template tag literals (and svg, css).

It is just using Prettier inside the template literal. This is a analogous to ESLint plugin format, but for embedded languages.

This is my first attempt at making an ESLint plugin, so expect this to be very naive.


Current issues

  • Trim remaining surrounding whitespace
  • Inherit indenting level
  • How are nested literals supposed to behave?
  • Should extract interpolations from the formatting process
  • Replacing the text seems to block further processing for nested templates

Try with the testbed

pnpm i
pnpm dev

Original

const name = `Rantanplan`
  const animals = [ 
    `dog`,"cat"]


        


export default createBeerBottle({
           drink: ({ url }) => html`
   ${url}

<div>
        <h1>It's a 404!</h1>

  </  div>
                                               ${
                                                                // My eyes bleed
                                                 name +     'dddd'}

                   <span>

                   ${animals.map((e,i)=>html`
                                                <span>
                                                  <div>     ${e} / ${i}   </div>
                                                    </span>
                   `)}
                       </span>



                   <hr />
 `,
});

With Prettier

const name = `Rantanplan`;
const animals = [`dog`, "cat"];

export default createBeerBottle({
  drink: ({ url }) => html`
    ${url}

    <div>
      <h1>It's a 404!</h1>
    </div>
    ${
      // My eyes bleed
      name + "dddd"
    }

    <span>
      ${animals.map(
        (e, i) => html`
          <span>
            <div>${e} / ${i}</div>
          </span>
        `,
      )}
    </span>

    <hr />
  `,
});

Current result

const name = `Rantanplan`;
const animals = [
    `dog`, "cat"
];

export default createBeerBottle({
  drink: ({ url }) => html` ${url}

<div>
  <h1>It's a 404!</h1>
</div>
${ // My eyes bleed name + 'dddd'}

<span>
  ${animals.map((e,i)=>html`
  <span>
    <div>${e} / ${i}</div>
  </span>
  `)}
</span>

<hr />
`
,
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published