Unable to get eslint working in Atom Editor - javascript

I'm totally lost at this point on how to get ESLint to install and function using Atom. So I'm going to post a step by step and would be really awesome if someone could help be get this working.
Atom: 1.19.5
Atom, linter 2.2.0
Atom, linter-eslint 8.2.1
I've uninstalled and reinstalled the Atom plugins and have disabled all other plugins besides those in Core and the 2 linters.
npm list -g --depth=0
All Global Installs:
├── create-react-app#1.0.4
├── create-react-native-app#1.0.0
├── eslint#4.6.1
├── express-generator#4.14.1
├── json-server#0.9.5
├── mocha#3.2.0
├── nodemon#1.11.0
├── npm#3.10.10
├── pushstate-server#2.2.1
├── react-native-cli#2.0.1
├── react-vr-cli#0.3.5
├── webpack#2.2.1
├── webpack-dev-server#2.3.0
└── yarn#0.21.3
These are the attempted steps I've done to get eslint to work in my Atom project:
npm install -g eslint
cd /into/project
eslint --init
? How would you like to configure ESLint? > User a popular style guide
? Which style guide do you want to follow? >Airbnb
? Do you use React? > y
? What format do you want your config file to be in? > JSON
Delete /node_modules
npm install
/project
/node_modules
.eslintrc.json
index.js
package.json
.eslintrc.json
{
"extends": "airbnb"
}
package.json
{
"name": "lint-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": "^4.6.1",
"eslint-config-airbnb": "^15.1.0",
"eslint-config-rallycoding": "^3.2.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.3.0"
}
}
index.js
This is just a file trying to get some type of results from eslint
Errors
[Linter] Error running ESLint (Open developer console)
Configuration for rule "jsx-a11y/anchor-has-content" is invalid: Value "[object Object]" no (or more than one) schemas match.
So went to eslint-plugin-jsx #168
No errors are appearing in the Atom developer console. But also nothing is happening with the Linter in the Atom editor. I can type gibberish and nothing happens.
Running Debug
DEBUG=eslint:* eslint .
Debug results:
Cannot find module 'eslint-config-airbnb'
Referenced from: /Users/user/development/lint-test/.eslintrc.json
Error: Cannot find module 'eslint-config-airbnb'
Referenced from: /Users/user/development/lint-test/.eslintrc.json
at ModuleResolver.resolve (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/util/module-resolver.js:74:19)
at resolve (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config/config-file.js:515:25)
at load (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config/config-file.js:584:26)
at configExtends.reduceRight.e (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config/config-file.js:421:36)
at Array.reduceRight (native)
at applyExtends (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config/config-file.js:403:28)
at loadFromDisk (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config/config-file.js:556:22)
at Object.load (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config/config-file.js:592:20)
at Config.getLocalConfigHierarchy (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config.js:226:44)
at Config.getConfigHierarchy (/Users/user/.nvm/versions/node/v6.9.5/lib/node_modules/eslint/lib/config.js:180:43)
At this point I'm assuming it's trying to read from the global not local
eslint eslint-config-airbnb error #465
updated .eslintrc.json to "extends": "eslint-config-airbnb",
Now again nothing is happening, run debug again
DEBUG=eslint:* eslint .
Still can't find the module
Try suggestions in Configuring Atom editor with eslint
At this point I'm still running into Cannot find module 'eslint-config-airbnb'
Followed npm eslint-config-airbnb
ran all the commands
New local package.json
"devDependencies": {
"eslint": "^4.6.1",
"eslint-config-airbnb": "^15.1.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.3.0"
}
npm install -g eslint-config-airbnb
New Global Modules
├── create-react-app#1.0.4
├── create-react-native-app#1.0.0
├── eslint#4.6.1
├── eslint-config-airbnb#15.1.0
├── eslint-plugin-import#2.7.0
├── UNMET PEER DEPENDENCY eslint-plugin-jsx-a11y#6.0.2
├── eslint-plugin-react#7.3.0
├── express-generator#4.14.1
├── install-peerdeps#1.1.3
├── json-server#0.9.5
├── mocha#3.2.0
├── nodemon#1.11.0
├── npm#3.10.10
├── pushstate-server#2.2.1
├── react-native-cli#2.0.1
├── react-vr-cli#0.3.5
├── webpack#2.2.1
├── webpack-dev-server#2.3.0
└── yarn#0.21.3
So now I can run DEBUG=eslint:* eslint . and can get some results. However nothing ever runs in Atom.
Results:
/Users/user/development/lint-test/index.js
1:1 error Definition for rule 'jsx-a11y/href-no-hash' was not found jsx-a11y/href-no-hash
1:7 error 'config' is assigned a value but never used no-unused-vars
1:24 error Unable to resolve path to module '../something' import/no-unresolved
1:39 error Missing semicolon semi
✖ 4 problems (4 errors, 0 warnings)
1 error, 0 warnings potentially fixable with the `--fix` option.
At this point I'm out of ideas on how to get Atom to actually work with eslint...

uncheck the setting "Use global ESLint installation" in linter-eslint of ATOM will make it correct

Without digging into the issue and finding specific point of failure I decided on a fresh start.
Delete global node modules.
Delete all NON core Atom plugins AND themes.
uninstall Atom.
reinstall Atom.
install ESLint and supporting dependencies only.
Doing that I was able to run ESLint with no issues. My assumption in all of this is there was a conflict in a plugin or theme. From there installing my core tool plugins was successful.

Related

ERROR Extension entrypoint(s) missing while I'm trying to package a developed vscode extension with vsce

I'm developing a VSCode extension to automate some edit & search processes. Everything runs Ok! in the Extension Development Host but when I try to package the extension with vsce inside the extension's folder the app responds with this error:
ERROR Extension entrypoint(s) missing. Make sure these files exist and aren't ignored by '.vscodeignore':
extension/extension.js
At the extension's manifest(package.json) the entrypoint to the extension code is defined in the "main" key:
...
"activationEvents": [
"onCommand:extension.findBlock"
],
"main": "./extension.js",
"contributes": {
"commands": [
{
"command": "extension.findBlock",
"title": "Find Block"
}
],
...
In the extension's folder everything is as the visual studio extension generator(yo) left it.
.
├── block_finder.code-workspace
├── CHANGELOG.md
├── extension.js
├── findBlock.png
├── jsconfig.json
├── node_modules
├── package.json
├── package-lock.json
├── prueba.txt
├── README.md
├── test
└── vsc-extension-quickstart.md
Am I missing something? I don't understand what could be happening. My VSCode version is 1.65.2 and vsce is 2.7.0. Thanks!
I came back to say that I solved the problem by uninstalling the npm manager. The version I had installed was old and I noticed that in the installation of the extension requirements it installed packages with warnings of deprecated versions. I uninstalled npm and did a clean install and my extension started working as expected. Sorry for leaving this post open and thanks for all the help you have given me.

How to structure a simple yarn package for local sharing

I want to create a simple yarn package that can be installed by multiple local yarn projects using yarn add link:/path/to/package. Imagine the package of the package to be shared looks like this
├── package.json
├── tsconfig.json
└── src
├── generated
│   ├── abc.js
│   ├── abc.d.ts
│   └── def.js
│   └── def.d.ts
My goal is that abc and def should be accessible like this
import * from "myPackage/abc"
Currently if I install the above package with yarn add link:/path/to/package then I have to do
import * from "myPackage/src/generated/abc"
I'm a rookie on making typescript packages so forgive me. Can someone point me in the right direction here?
I've tried the suggestion here but it doesn't make a difference.
So it seems I need to set exports and typesVersions in package.json
"exports": {
"./": "./src/generated/"
},
"typesVersions": {
"*": {
"abc": [
"./src/generated/abc.d.ts"
],
"def": [
"./src/generated/def.d.ts"
],
}
},

Imported class in angular is undefined

I have an npm project with the following structure:
app-dep
├── dist
│ ├── bundle.js
│ └── bundle.js.map
├── node_modules/
├── package.json
├── package-lock.json
├── src
│ ├── base-component.ts
│ ├── factory.ts
│ ├── app.ts
│ └── modules/
├── tsconfig.json
└── webpack.config.js
My app.ts code has an App class that utilizes all .ts files inside src/
export default class App extends HTMLElement { //some-content }
I use webpack to build a bundle.js inside the dist/ folder.
I have another angular project where I install this app-dep project using
npm install --save ../app-dep
When I try to use it in my angular component:
import App from 'app-renderer/dist/bundle';
ngOnInit() {
window.customElements.define('micro-app', App);
}
I get this error:
Failed to execute 'define' on 'CustomElementRegistry': parameter 2 is not of type 'Function'
When I try to log it on console, all I can see is undefined.
It seems that I can't import basic functions even.
Can you tell me what's wrong?
I think the problem has to do with the import or the pack, I ellaborate below with the steps to follow.
Also, make sure that you are exporting all the classes that you want to make available from the outside.
For TypeScript libraries
You can simply use "tsc" and then pack the generated code inside the dist folder with "npm pack" and install the dependency in your application with "npm install ".
This may get complicated due to the different module systems and bundlers, check this links for more info on Webpack:
https://marcobotto.com/blog/compiling-and-bundling-typescript-libraries-with-webpack/
https://webpack.js.org/guides/author-libraries/
For CSS libraries
The "npm pack" has to be executed in the root folder. You may want to process your styles with sass before and only pack the result.
For Angular libraries
By default with Angular CLI when you build a library project the code is generated in /dist/mylibrary folder.
If you want to use that code in other project, the steps are:
Build your library with "ng build mylibrary" (add --prod for production).
From your library, move into /dist/mylibrary folder and then execute a "npm pack", that will generate a tgz package.
From your application in which you want to use the library execute "npm install " to install the dependency.
To import code from the library use "import * from 'mylibrary'"
Other option would be using "npm link", that creates a link between your node_nodules and the library code as explained here:
https://www.willtaylor.blog/complete-guide-to-angular-libraries/
That would be the way to go with local libraries, usually these libraries are published into Npm repository (public or private) and installed remotely with "npm install ". These steps are only for local usage.

React Native 'unable to resolve module `moment-timezone`' despite it being in node_modules

I'm trying to run a React Native project, lucy-app, which manages its packages through Yarn. In the src directory there is a utils.js:
Kurts-MacBook-Pro-2:lucy kurtpeek$ tree lucy-app/src -L 1
lucy-app/src
├── actions.js
├── api.js
├── app.js
├── components
├── containers
└── utils.js
Both moment and moment-timezone appear in package.json:
{
"name": "app",
"version": "0.0.1",
"private": true,
"scripts": {
},
"dependencies": {
"moment": "^2.19.0",
"moment-timezone": "^0.5.14",
There is a moment-timezone directory in node_modules:
/Users/kurtpeek/Documents/dev/lucy/lucy-app/node_modules
Kurts-MacBook-Pro-2:node_modules kurtpeek$ find . -name 'moment-timezone'
./moment-timezone
The utils.js file imports moment-timezone as follows:
import moment from 'moment-timezone';
However, when I try to run react-native run-ios, I get the following error:
error: bundling failed: Error: Unable to resolve module `moment-timezone` from `/Users/kurtpeek/Documents/Dev/lucy/lucy-app/src/utils.js`: Module does not exist in the module map or in these directories:
/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules
This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
1. Clear watchman watches: `watchman watch-del-all`.
2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
3. Reset Metro Bundler cache: `rm -rf $TMPDIR/react-*` or `npm start -- --reset-cache`. 4. Remove haste cache: `rm -rf $TMPDIR/haste-map-react-native-packager-*`.
at ModuleResolver.resolveDependency (/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:311:1719)
at ResolutionRequest.resolveDependency (/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:96:16)
at DependencyGraph.resolveDependency (/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/node-haste/DependencyGraph.js:269:4352)
at /Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:201:36
at Generator.next (<anonymous>)
at step (/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:256:306)
at /Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:256:536
at new Promise (<anonymous>)
at /Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:256:217
at addDependency (/Users/kurtpeek/Documents/Dev/lucy/lucy-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:256:92)
BUNDLE [ios, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.
Following the suggestions, I've tried rm -rf node_modules followed by yarn install, but I'm still getting the same error. Any ideas what is going wrong here?

ESLint configuration woes

I am trying to use an eslint workflow. I have installed Node via nvm and the nessary plugins globally:
├── babel-eslint#6.0.2
├── eslint#2.7.0
├── eslint-config-angular#0.5.0
├── eslint-config-semistandard#6.0.1
├── eslint-config-standard#5.1.0
├── eslint-plugin-angular#1.0.0
├── eslint-plugin-promise#1.1.0
├── eslint-plugin-standard#1.3.2
├── npm#3.8.3
├── standard#6.0.8
And locally in my project:
"devDependencies": {
"eslint": "2.7.0",
"eslint-config-angular": "0.5.0",
"eslint-config-standard": "5.1.0",
"eslint-config-semistandard": "6.0.1",
"eslint-plugin-angular": "1.0.0",
"eslint-plugin-promise": "1.1.0",
"eslint-plugin-standard": "1.3.2"
},
And I have set up an .eslintrc.json file in my project root:
{
"env": {
"browser": 1
},
"extends": "semistandard",
"plugins": [
"standard","angular"
],
"globals": {
"angular": 1,
"$": 1,
"angularDragula": 1
}
}
The Atom ESlint and standard-formatter plugins find and respect my config file, but it not the command line or the Sublime Linter. It does not read the config, so I get errors flagged:
Which make it obvious it's not reading the settings. What am I doing wrong here? As I said, it works in Atom but not command line or Sublime (which uses the command-line options).
I'd recommend against using a global installation of ESLint. If you want to run it to lint the files in your project, you can use:
node_modules/.bin/eslint feedback-alerts.controller.js
Or, better yet, create an npm script for the task. In your package.json, you can add:
"scripts": {
"lint": "eslint feedback-alerts.controller.js"
}
Furthermore, it looks like you are using a config file that is not in your project root (~/.eslintrc.json is in your user root, not project root). ESLint will do its own config resolution, so you should not have to specify the path to the config file except in advanced cases.

Categories