Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

[Error] Global Node Objects '__dirname' and '__filename' #145

Closed
andrewjtorres opened this issue Jan 20, 2017 · 8 comments
Closed

[Error] Global Node Objects '__dirname' and '__filename' #145

andrewjtorres opened this issue Jan 20, 2017 · 8 comments

Comments

@andrewjtorres
Copy link

What version of TypeScript are you using?
2.0.3

What version of typescript-eslint-parser are you using?
1.0.2

What code were you trying to parse?

export const sequelizeData = new Umzug({

  migrations: {
    params: [sequelize.getQueryInterface(), Sequelize],
    path: path.resolve(__dirname, './seeders'),
    pattern: /^[A-Z]+\.js$/i,
  },

  storage: 'sequelize',

  storageOptions: {
    modelName: 'SequelizeData',
    sequelize,
    tableName: 'sequelize_data',
  },

});

What did you expect to happen?
This project was originally pure JavaScript, my team and I are currently in the process of migrating it to TypeScript. Prior to the migration, the line: path: path.resolve(__dirname, './seeders'),, would pass our linting rules.

What happened?
After implementing 'typescript-eslint-parser', the line: path: path.resolve(__dirname, './seeders'),, results in a 'no-undef' error.

@nzakas
Copy link
Member

nzakas commented Jan 22, 2017

Can you please paste in the complete error you're seeing?

@andrewjtorres
Copy link
Author

No problem. The following image is the error produced by ESLint:

no-undef

I am not sure if this has any relevance at all, but it looks like '__dirname' in the image has 3 underscores preceding the word "dirname" as opposed to the expected 2.

@soda0289
Copy link
Member

soda0289 commented Feb 7, 2017

This looks to be a bug in typescript. Any variable, function, or class declaration that starts with two underscores will have three when parsed.

Related:
microsoft/TypeScript#11902
microsoft/TypeScript#3268

Will look into a possible fix.

@soda0289
Copy link
Member

I have opened a new typescript issue for this bug:
microsoft/TypeScript#14013

@JamesHenry
Copy link
Member

Thanks for hunting that down, @soda0289! I'll ping the TypeScript team if they don't pick up on that issue soon

@soda0289
Copy link
Member

Got a response from typescript. We can use the unescapeIdentifier function to return the real identifier name. Will submit PR soon.

soda0289 added a commit to soda0289/typescript-eslint-parser that referenced this issue Feb 14, 2017
…slint#145)

Typescript will prepend an underscore to an identifier when it starts
with two leading underscores. This causes rules to break in eslint
becuase identifiers do not match those in the source code.
soda0289 added a commit to soda0289/typescript-eslint-parser that referenced this issue Feb 14, 2017
…lint#145)

Typescript will prepend an underscore to an identifier when it starts
with two leading underscores. This causes rules to break in eslint
becuase identifiers do not match those in the source code.
@JamesHenry
Copy link
Member

@ajtorres9 This should now be fixed on master. NPM update will likely follow once the other open PR is merged

@andrewjtorres
Copy link
Author

Thanks all for your efforts, I appreciate it. 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants