I am trying to run the ESLint JSDoc plugin
When I run npx eslint . airbnb rules are enforced but not the jsdoc ones requiring to add JSDoc.
Am I missing something ?
Here is a test repo
package.json
{
"name": "eslint-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": "^6.7.2",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jsdoc": "^18.4.3"
}
}
index.js
const fn = (a) => {
console.log('a :', a);
return a;
};
module.exports = { fn };
You are missing the ESLint configuration file. Add .eslintrc.js to the root of your project. Then copy the following basic configuration:
module.exports = {
root: true,
plugins: ['jsdoc', 'import'],
extends: [
'eslint:recommended',
'plugin:jsdoc/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'airbnb-base'
]
}
See Configuring ESLinf for more informaion.
Related
I'm creating webpack5 setup for an small app and while doing I'm facing the below mentioned issue. Please suggest the way to resolve
Issue Snapshot
Module not found: Error: Can't resolve 'faker' in 'C:\Gowtham\micro-frontend-training\products\src'
resolve 'faker' in 'C:\Gowtham\micro-frontend-training\products\src'
Parsed request is a module
using description file: C:\Gowtham\micro-frontend-training\products\package.json (relative path: ./src)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
C:\Gowtham\micro-frontend-training\products\src\node_modules doesn't exist or is not a directory
looking for modules in C:\Gowtham\micro-frontend-training\products\node_modules
single file module
using description file: C:\Gowtham\micro-frontend-training\products\package.json (relative path: ./node_modules/faker)
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\Gowtham\micro-frontend-training\products\node_modules\faker is not a file
.js
Folder Structure
folder structure
webpack.config.js
module.exports = {
mode: "development",
};
package.json
{
"name": "products",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"faker": "^6.6.6",
"webpack": "^5.67.0",
"webpack-cli": "^4.9.2"
}
}
src/index.js
import faker from "faker";
let products = "";
for (let i = 0; i < 3; i++) {
const name = faker.commerce.productName();
products += `<div>${name}</div>`;
}
console.log(products);
Try with following package.json...
{
"name": "products",
"version": "1.0.0",
"description": "",
"main": "dist/main.js",
"scripts": {
"prestart": "webpack",
"start": "node ."
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"faker": "^5.5.3",
"webpack": "^5.67.0",
"webpack-cli": "^4.9.2"
}
}
Do a fresh install and run npm start...
My main code. I has "require('node-rsa')" which in node_modules folder. Is it possible to create one file from this code?
a.js
var testFunct = function test(message) {
const NodeRSA = require('node-rsa');
const key = new NodeRSA();
var k = key.generateKeyPair();
var p = k.exportKey('pkcs1');
return p};
console.log(testFunct())
package.json
{
"name": "pol",
"version": "1.0.0",
"description": "",
"main": "a.js",
"dependencies": {
"node-rsa": "^1.1.1",
"build": "webpack a.js b.js"
},
"devDependencies": {
"webpack": "^5.58.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
webpack.config.js
module.exports = {
entry: ['a.js'],
output: {
path: './build',
filename: 'bundle.js'
}
}
Add this entry to the scripts section of your package.json:
"build": "webpack"
This will trigger webpack, when you run the build action.
I'm new to coding and I'm trying to do what the lecturer is doing. We're looking at webpacks but everytime I try to use the command "npx webpack" it comes up with
/home/ubuntu/workspace/assignment1/hellowp/webpack.config.json: Unexpected token m in JSON at position 0"
How do I fix this?
module.exports = {
entry: './src/app.js',
output: {
filename: 'app.bundle.js',
path: __dirname + '/dist'
}
};
package.json:
{
"name": "hellowp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^4.10.1",
"webpack-cli": "^2.1.4"
},
"dependencies": {
"jquery": "^3.3.1"
}
}
app.js
import $ from "jquery";
$(document).ready(function(){
$('#intro').html("Hello Webpack");
})
<div id = 'intro'></p>
<script src='./dist/app.bundle.js'></script>
//whats in my html
Change filename to webpack.config.js (not .json)
package.json
{
"name": "learningmocha",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha && mocha test --require blanket --reporter html-cov > coverage.html"
},
"author": "",
"license": "ISC",
"devDependencies": {
"blanket": "^1.2.3",
"chai": "^3.5.0",
"mocha": "^3.2.0"
},
"config": {
"blanket": {
"pattern": [ "index.js" ],
"data-cover-never": "node-module"
}
}
}
I am using Mocha for testing in nodejs. when i run npm test after adding html-cov in the test script of my package.json as show above then it give me error
"Error: invalid reporter "html-cov"
You can see more in this image
html-cov was dropped in 3.0.0 [1]
[1] https://github.com/mochajs/mocha/issues/2356
I want to copy all files to another dir (with grunt-contrib-copy) except files that are listed in .gitignore.
This is my current setup:
.gitignore:
/vendor
/node_modules
package.json:
{
"name": "grunt-cpy",
"version": "1.0.0",
"description": "",
"main": "Gruntfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gitignore-globs": "^0.1.1",
"grunt": "^0.4.5",
"grunt-cli": "~0.1.11",
"grunt-contrib-copy": "^0.7.0",
"grunt-contrib-clean": "^0.6.0"
}
}
Gruntfile.js
module.exports = function (grunt) {
var parse = require('gitignore-globs');
var globs = parse('.gitignore', { negate: true } );
grunt.log.ok( globs );
// Project configuration.
grunt.initConfig({
pkg : grunt.file.readJSON( 'package.json' ),
clean: {
pre_build: [
'build/'
]
},
copy: {
build: {
options : {
mode :true
},
src: [
'**',
globs
],
dest: 'build/'
}
}
});
grunt.loadNpmTasks( 'grunt-contrib-clean' );
grunt.loadNpmTasks( 'grunt-contrib-copy' );
grunt.registerTask( 'default', [ 'clean:pre_build', 'copy'] );
};
Debug output of globs:
!/vendor,!/vendor/**,!/node_modules,!/node_modules/**
But it doesn't work this way. It just copies everything. I also tried the package 'gitignore-to-glob' and 'grunt-copy-to'. Can somebody help to archive this?
I'm on Windows.