Git Product home page Git Product logo

Comments (5)

kentcdodds avatar kentcdodds commented on May 17, 2024

Hmmm... Weird. I can look into it another time. But you're welcome to dig a little too figure out why that's happening :-)

from prettier-eslint.

bnjmnt4n avatar bnjmnt4n commented on May 17, 2024

Seems like you're running format(options) without passing in the code to format.

from prettier-eslint.

exdeniz avatar exdeniz commented on May 17, 2024

@demoneaux I try now code

const format = require('prettier-eslint')
const sourceCode = `const {foo} = bar`

// notice, no semicolon in the original text
const options = {
  eslintConfig: {
    rules: {
      semi: ['error', 'never'],
    },
  },
  prettierOptions: {
    bracketSpacing: true,
  },
}

const formatted = format(sourceCode, options)

// notice no semicolon in the formatted text
console.log(formatted) // const { foo } = bar

and return

prettier-eslint error: prettier formatting failed TypeError: Cannot read property '0' of undefined
    at new Parser (/Users/exdeniz/Project/temp/test/node_modules/babylon/lib/index.js:1529:45)
    at Object.parse (/Users/exdeniz/Project/temp/test/node_modules/babylon/lib/index.js:6657:10)
    at Object.format (/Users/exdeniz/Project/temp/test/node_modules/prettier-eslint/node_modules/prettier/index.js:42:21)
    at prettify (/Users/exdeniz/Project/temp/test/node_modules/prettier-eslint/dist/index.js:64:31)
    at format (/Users/exdeniz/Project/temp/test/node_modules/prettier-eslint/dist/index.js:55:18)
    at Object.<anonymous> (/Users/exdeniz/Project/temp/test/app.js:16:19)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

from prettier-eslint.

exdeniz avatar exdeniz commented on May 17, 2024

I found work example, but eslintConfig not working, use rules for eslintrc.

const format = require('prettier-eslint')
const sourceCode = 'const {foo} = bar'

// notice, no semicolon in the original text
const eslintConfig = {
    rules: {
      semi: ['error', 'never'],
    }
    }
  const prettierOptions = {
    bracketSpacing: true,
  }

const formatted = format({ text: sourceCode, eslintConfig: eslintConfig, prettierOptions: prettierOptions })

// notice no semicolon in the formatted text
console.log(formatted) // const { foo } = bar

from prettier-eslint.

kentcdodds avatar kentcdodds commented on May 17, 2024

Could you take a look at this? #4

from prettier-eslint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.