sheerun / prettier-standard

Formats with Prettier and lints with ESLint+Standard! (✿◠‿◠)
MIT License
867 stars 44 forks source link

Errors while linting TypeScript #108

Open mehmetnyarar opened 4 years ago

mehmetnyarar commented 4 years ago

I've installed prettier-standard to my monorepo project. When I run prettier-standard --lint on the root, I get the following errors:


   7 | export interface EnvVars {
   8 |   HOST_SSL?: string
>  9 |   HOST_DOMAIN?: string
     |   ^
  10 |   SERVER_PORT?: string
  11 |   WEB_CLIENTS?: string
  12 |   CORS_WHITELIST?: string
error  Parsing error: Unexpected token, expected "]"

  10 | export const getRequired = (config: RequiredConfig = {}) => {
  11 |   return Object.keys(config).reduce((required, key) => {
> 12 |     return config[key as keyof EnvVars] ? required.concat(key) : required
     |                       ^
  13 |   }, [] as string[])
  14 | }
error  'Record' is not defined  no-undef
error  Parsing error: Unexpected token, expected ";"

  15 |  * Console methods.
  16 |  */
> 17 | export type ConsoleMethod = keyof Omit<Console, 'Console'>
error  Parsing error: Using the export keyword between a decorator and a class is not allowed. Please use `export @dec class` instead.

  3 | 
  4 | @Resolver()
> 5 | export class CommonResolver {

Am I missing something?

sheerun commented 4 years ago

I guess you forgot ;?

jdtzmn commented 4 years ago

I'm having this issue as well, with static modifiers and whatnot:

Screen Shot 2020-08-06 at 8 30 20 AM
jdtzmn commented 4 years ago

Is this package expected to work with TypeScript or not?

I assumed it was because it includes @typescript-eslint/parser, but then in the ignoring files section it has the example of ignoring **/*.ts, so now I'm not sure.

sheerun commented 4 years ago

it works in my case, what's your typescript and prettier-standard version in package.json? how do you run it?

jdtzmn commented 4 years ago

You are correct. I figured out that my issue was with eslint. static's can't be private.

ahuggins-nhs commented 4 years ago

I'm having the same issues as the OP. There's actually a couple of different scenarios:

Combinations of:

pretter-standard@16.4.1
typescript@4.0.2
@typescript-eslint/parser@4.0.1

or

pretter-standard@16.4.1
typescript@3.9.7
@typescript-eslint/parser@3.0.0

Results in eslint parsing errors.

Rolling back to 16.3.0 resolves my issue.

RogWilco commented 4 years ago

Encountered the same problem today, and can also confirm rolling back to 16.3.0 seems to resolve it. In my case it seems to be choking on this:

export type ThrowableType = new () => Error

Which results in:

  5:33  error  Parsing error: Unexpected token, expected ";"

  3 |  * used when specifying which type of error will be caught.
  4 |  */
> 5 | export type ThrowableType = new () => Error
    |                                 ^
  6 | 
  7 | /**
  8 |  * A function containing the code to be executed as part of a try block

✖ 1 problem (1 error, 0 warnings)

This behavior can be observed in the public repo I'm working in here (running yarn lint will reproduce the issue).

ofbeaton commented 4 years ago

Came here because of the same types of problems.

  15:3  error  Parsing error: Unexpected token
  13 | export interface testConnInfo {
  14 |   db?: Connection
> 15 |   redis?: Redis.Redis
     |   ^
  16 | }

or

  191:25  error  Parsing error: Unexpected token, expected ","

  189 |     })
  190 |
> 191 |     expect(response.data!.users!).toHaveLength(4)
      |                         ^
  192 |
  193 |     // TODO: verify the 4 users we want to see
  194 |   })

or

  47:27  error  Parsing error: Unexpected token, expected ";"

  45 |   beforeAll(async () => {
  46 |     connInfo = await testConnOpen()
> 47 |     redis = connInfo.redis!
     |                           ^
  48 |     userRepository = getRepository(User)
  49 |   })
  50 |

problems occur with 16.4.1, 16.4.0 (how come neither of these are tagged in github master repo?)

All of them go away when you revert to 16.3.0 the last repo tagged version.

einSelbst commented 3 years ago

When setting parserOptions.project for typescript in the eslint config I also have the problem that prettier-standard seem to have issues picking up the config.

Error: Error while loading rule '@typescript-eslint/await-thenable': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Occurred while linting /Users/einselbst/Workspace/einselbst/feehikel/src/pages/_app.tsx

Rolling back to 16.3.0 does also fix this issue.

spaceoi commented 3 years ago

Came here because of the same types of problems.

  15:3  error  Parsing error: Unexpected token
  13 | export interface testConnInfo {
  14 |   db?: Connection
> 15 |   redis?: Redis.Redis
     |   ^
  16 | }

or

  191:25  error  Parsing error: Unexpected token, expected ","

  189 |     })
  190 |
> 191 |     expect(response.data!.users!).toHaveLength(4)
      |                         ^
  192 |
  193 |     // TODO: verify the 4 users we want to see
  194 |   })

or

  47:27  error  Parsing error: Unexpected token, expected ";"

  45 |   beforeAll(async () => {
  46 |     connInfo = await testConnOpen()
> 47 |     redis = connInfo.redis!
     |                           ^
  48 |     userRepository = getRepository(User)
  49 |   })
  50 |

problems occur with 16.4.1, 16.4.0 (how come neither of these are tagged in github master repo?)

All of them go away when you revert to 16.3.0 the last repo tagged version.

solved the optional chaining problem by replacing dependency "prettierx"(0.11 in package) to newest version(currently 0.17). You can try if it could solve other problems.

HoraceShmorace commented 2 years ago

This is pretty old and I'm running into the same problem. Rolling back to 16.3.0 definitely fixed the issue for me.

einSelbst commented 2 years ago

@HoraceShmorace this library doesn't seem to be maintained anymore