.eslintrc.js doesn't work with rules "off" - react-native

native and have a problem with configuring eslint.
This is my .eslintrc.js.
module.exports = {
"extends": "airbnb",
"parser": "babel-eslint",
"env": {
"jest": true,
},
"plugins": [
"react",
"node"
],
"rules": {
"no-use-before-define": "off",
"react/jsx-filename-extension": "off",
"node/no-unsupported-features/es-syntax": ["error", {
"version": ">=6.0.0",
"ignores": ["modules", "destructuring"]
}],
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/prop-types": "off",
}
};
In App.js,
const { navigation } = this.props;
I got the eslint error.
[eslint] Destructuring are not supported yet on Node 4.0.0. (node/no-unsupported-features)
[eslint] 'navigation' is missing in props validation (react/prop-types)
And also in In App.js,
<View style={styles.container}>
<UpArrow title="cancel" />
<SecondsSpinner seconds={this.state.imageTime} changeImageTime={this.changeImageTime} />
<DownArrow title="save" />
</View>
I got error
[eslint] JSX not allowed in files with extension '.js' (react/jsx-filename-extension)
So I
turned off "react/prop-types",
set "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }]
set "ignores": ["destructuring"].
But they dosen't work.
I don't know why and how to solve this.
Is there any other file to config eslint?
Thanks in advance.
EDIT1) "ignores": ["modules"] works. so weird.
EDIT2) I am using vscode and got errors on the editor on and on, so I thought because of .eslintrc file.
But now I think it's problem of vscode. I set
"eslint.options": { "configFile": "/Users/com/vscode/AwesomeProject/.eslintrc.js" }
in Workspace Settings then it works

Try:
module.exports = {
"extends": "airbnb",
"parser": "babel-eslint",
"env": {
"jest": true,
},
"plugins": [
"react",
"node"
],
"rules": {
"no-use-before-define": 0,
"react/jsx-filename-extension": 0,
"node/no-unsupported-features/es-syntax": ["error", {
"version": ">=6.0.0",
"ignores": ["modules", "destructuring"]
}],
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/prop-types": 0,
}
};

Related

Vue Jest Invalid or unexpected token

I'm new to Jest and Vue, but I'm getting an error in one of my tests.
The error is:
Test suite failed to run
/...../node_modules/element-ui/lib/theme-chalk/table-column.css:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){#charset "UTF-8";.el-checkbox,.el-checkbox__input{white-space:nowrap;display:inline-block;position:relative}.el-checkbox{color:#606266;font-weight:500;font-size:14px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;margin-right:30px}.el-checkbox.is-bordered{padding:9px 20px 9px 10px;border-radius:4px;border:1px solid #DCDFE6;-webkit-box-sizing:border-box;box-sizing:border-box;line-height:normal;height:40px}.el-checkbox.is-bordered.is-checked{border-color:#409EFF}.el-checkbox.is-bordered.is-disabled{border-color:#EBEEF5;cursor:not-allowed}.el-checkbox.is-bordered+.el-checkbox.is-bordered{margin-left:10px}.el-checkbox.is-bordered.el-checkbox--medium{padding:7px 20px 7px 10px;border-radius:4px;height:36px}.el-checkbox.is-bordered.el-checkbox--medium .el-checkbox__l
SyntaxError: Invalid or unexpected token
Here's my package.json file:
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
".*\\.(vue)$": "vue-jest",
".*\\.(js)$": "babel-jest"
},
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js",
"^#/(.*)$": "<rootDir>/src/$1"
},
"testPathIgnorePatterns": [
"<rootDir>/(build|docs|node_modules)/*"
],
"testEnvironment": "node"
},
"babel": {
"presets": [
[
"#babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
},
I don't understand why node_modules isn't being excluded, but even if they aren't excluded why isn't the .css file being mocked?
I suspected the issue was jest was not reading my config from package.json.
To verify this I used the jest --showConfig. Indeed, it was different from package.json.
I then created a new config file, jest.json and I changed the test script in package.json to be "test": "jest --config jest.json"
This is the contents of my config:
{
"verbose": true,
"automock": false,
"globals": {
"_Table": {"name": "el-table"},
"_TableColumn": {"name": "el-table-column"}},
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
".*\\.(vue)$": "vue-jest",
".*\\.(js)$": "babel-jest"
},
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js",
"^#/(.*)$": "<rootDir>/src/$1"
},
"testPathIgnorePatterns": [
"<rootDir>/(build|docs|node_modules)/"
]
}
There are a few more issues, but this was the main one.

Vue PWA Plugin - Manifest doesn't use my config attributes

It's very strange. I installed the VuePWA-Plugin and configured it in the package.json like this:
"pwa": {
"name": "Poolio",
"themeColor": "#205c94",
"msTileColor": "#205c94",
"display": "fullscreen",
"appleMobileWebAppCapable": "yes",
"appleMobileWebAppStatusBarStyle": "#205c94",
"pwa.iconPaths": {
"favicon32": "./img/icons/favicon-32x32.png",
"favicon16": "./img/icons/favicon-16x16.png",
"favicon96": "./img/icons/favicon-96x96.png",
"appleTouchIcon": "./img/icons/apple-icon-152x152.png",
"msTitleImage": "./img/icons/ms-icon-144x144.png"
}
},
But it doesn't use any of my settings in the manifest.json (beside of the name, but this must be used by another setting, cause it doesn't change, if I change it)
I asked myself where it takes the themeColor and so I searched in the hole app folder for the hexcode #4DBA87, which is written in the manifest. But didn't find anything...
Heres the manifest output:
{
"name": "Poolio",
"short_name": "Poolio",
"theme_color": "#4DBA87",
"icons": [
{ "src": "./img/icons/android-chrome-192x192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "./img/icons/android-chrome-512x512.png", "sizes": "512x512", "type": "image/png" },
{ "src": "./img/icons/android-chrome-maskable-192x192.png", "sizes": "192x192", "type": "image/png", "purpose": "maskable" },
{ "src": "./img/icons/android-chrome-maskable-512x512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
],
"start_url": ".",
"display": "standalone",
"background_color": "#000000"
}
You can put all your manifest options inside pwa.manifestOptions. It would be something like this inside your vue.config.js:
module.exports = {
pwa: {
manifestOptions: {
name: "App Name",
short_name: "Short Name",
start_url: "./",
display: "standalone",
theme_color: "#000000",
icons: [
{
src: "./favicon.svg",
sizes: "512x512",
type: "image/svg+xml",
purpose: "any maskable",
},
],
},
themeColor: "#4DBA87",
msTileColor: "#000000",
appleMobileWebAppCapable: "yes",
appleMobileWebAppStatusBarStyle: "black",
iconPaths: {
maskicon: null,
favicon32: "./favicon32.png",
favicon16: "./favicon16.png",
appleTouchIcon: null,
msTileImage: null,
},
// configure the workbox plugin
workboxPluginMode: "GenerateSW",
},
};
Check out LinusBorg answers to this issue.
#vue/cli-plugin-pwa plugin internally uses webpack's workbox plugin. The color #4DBA87 you are getting is the default color set by the plugin.
You can read more about this plugin configuration here, https://www.npmjs.com/package/#vue/cli-plugin-pwa
To configure it to your liking via package.json you have to put your configurations inside the vue property. eg:
"vue": {
"pwa": {
"name": "Poolio",
"themeColor": "#205c94",
"msTileColor": "#205c94",
"appleMobileWebAppCapable": "yes",
"appleMobileWebAppStatusBarStyle": "#205c94",
"iconPaths": {
"favicon32": "./img/icons/favicon-32x32.png",
"favicon16": "./img/icons/favicon-16x16.png",
"favicon96": "./img/icons/favicon-96x96.png",
"appleTouchIcon": "./img/icons/apple-icon-152x152.png",
"msTitleImage": "./img/icons/ms-icon-144x144.png"
},
"workboxPluginMode": "InjectManifest",
"workboxOptions": {
"swSrc": "src/service-worker.js",
},
}
}

How to add tno-unused-vars errors in #vue/cli

In #vue/cli 4.0.5 app I want to add no-unused-vars errors(both in app and in phpstorm )
and I added this option in .eslintrc.js, which contains:
module.exports = {
root: true,
env: {
node: true
},
'extends': [
'plugin:vue/essential',
'eslint:recommended'
],
rules: {
'no-console': 'error',
'no-debugger': 'error',
"no-unused-vars": "error",
'no-undef': "error",
},
parserOptions: {
parser: 'babel-eslint'
}
}
But I di not see no-unused-vars errors event I restart yarn server.
Are there some other options ?
Thanks!
I don't know how your configurations are set, but you can always add the eslintConfig on package.json file, like this:
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"rules": {
"no-unused-vars": "error"
}
}

Vue-Cli, how to disable camel case warnings

I am trying to disable the Eslint camelcase rule by setting it to either "off" or 0 in my package.json file. Any idea why it isn't working?
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended",
"#vue/typescript/recommended"
],
"parserOptions": {
"ecmaVersion": 2020
},
"rules": {
"camelcase": "off"
},
"overrides": [
{
"files": [
"**/__tests__/*.{j,t}s?(x)",
"**/tests/unit/**/*.spec.{j,t}s?(x)"
],
"env": {
"mocha": true
}
}
]
}
You can keep the settings as per your requirement:
"rules": {
"properties": "never",
"ignoreDestructuring": true,
"ignoreImports": false
},
Here is the default setting and description:
"properties": "always" (default) enforces camelcase style for property names
"ignoreDestructuring": false (default) enforces camelcase style for destructured identifiers
"ignoreImports": false (default) enforces camelcase style for ES2015 imports
More info here: https://eslint.org/docs/rules/camelcase

ElementUI tests throw ReferenceError: _Message is not defined

Bug report on ElementUI
I am using On-demand loading of ElementUI components. I've followed the instructions correctly and it works just fine when running the app.
The problem arises when I try to test with Jest and Vue test utils. None of the components I am importing seem to be found, so I get this error when running my tests:
ReferenceError: _Message is not defined
I get the same error for any of the other components, that my test touches.
On the bug report I mentioned above, I am being suggested that my babel configuration is not being applied in my testing environment? Or its something about my Jest configuration. I've tried various things to fix this:
Doing a manual mocks
Spying on the component
Importing the whole ElementUI package inside my test
Updating Jest configuration
Nothing seems to work and I have no idea what is wrong...
bebel.config.js
module.exports = {
presets: [
'#vue/app',
],
plugins: [
[
'component',
{
libraryName: 'element-ui',
styleLibraryName: 'theme-chalk',
},
],
],
};
jest.config.js
module.exports = {
// roots: ['<rootDir>/src/', '<rootDir>/tests/'],
moduleFileExtensions: [
'js',
'jsx',
'json',
'vue',
],
transform: {
'^.+\\.vue$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
'^.+\\.jsx?$': 'babel-jest',
},
transformIgnorePatterns: [
'/node_modules/(?!element-ui)',
],
moduleNameMapper: {
'^#/(.*)$': '<rootDir>/src/$1',
'^.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
},
snapshotSerializers: [
'jest-serializer-vue',
],
testMatch: [
'**/tests/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)',
],
testURL: 'http://localhost/',
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
],
collectCoverage: true,
coverageReporters: ['lcov', 'text-summary'],
};
I have a couple of suggestions for you here:
change this in jest.config.js
module.exports = {
moduleFileExtensions: [
'js',
'jsx',
'json',
'vue',
],
transform: {
'^.+\\.vue$': 'vue-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
'^.+\\.(js|jsx)?$': 'babel-jest'
},
moduleNameMapper: {
'^#/(.*)$': '<rootDir>/src/$1',
'^.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
},
snapshotSerializers: [
'jest-serializer-vue',
],
testMatch: [
'**/tests/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)',
],
testURL: 'http://localhost/',
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
],
collectCoverage: true,
coverageReporters: ['lcov', 'text-summary'],
};
and this in babel.config.js
module.exports = {
presets: [
'#vue/app',
],
plugins: [
[
'component',
{
libraryName: 'element-ui',
styleLibraryName: 'theme-chalk',
},
],
],
"env": { "test": { "plugins": ["transform-es2015-modules-commonjs", "dynamic-import-node"] } }
};
Also I believe #babel/plugin-transform-modules-commonjs is needed in yarn.
Let me know if this works.