I would like to apply an ESLint rule that forces newlines before and after /* block comments / but not around /* JSDoc comments */. For those, I'd like a newline before the comment only, but I can't figure out how to set up a rule to do this. Any help would be appreciated.
My goal for valid comments:
const a = 1;
/*
* This multiline comment has
* newlines above and below it
*/
const b = 2;
/**
* This javadoc describes the function
* direction below it and should have
* a newline above it, but not below
*/
const myFunc = () => {}
I've attempted setting up an ignorePatter within the lines-around-comment setting but it either applies to both types of block comments, neither, or just crashes ESLint.
This attempt ignores both types of block comments for some reason
...
"lines-around-comment": [
"warn",
{
"afterBlockComment": true,
"beforeLineComment": true
"ignorePattern": "\\*\\*"
}
],
...
This one applies to neither
...
"lines-around-comment": [
"warn",
{
"afterBlockComment": true,
"beforeLineComment": true
"ignorePattern": "\\*"
}
],
...
And this one crashes ESLint
...
"lines-around-comment": [
"warn",
{
"afterBlockComment": true,
"beforeLineComment": true
"ignorePattern": "*"
}
],
...
I'll also add that I am ignoring (via an exception) the requirement for spaced-comments when using JSDoc via this config:
...
"spaced-comment": [
"error",
"always",
{ "exceptions": ["*"] }
]
...
Full ESLint file:
{
"root": true,
"plugins": [],
"parser": "#babel/eslint-parser",
"extends": "eslint:recommended",
"rules": {
"array-callback-return": "error",
"no-self-compare": "error",
"no-template-curly-in-string": "error",
"curly": [
"warn",
"all"
],
"default-case": "error",
"dot-notation": "warn",
"eqeqeq": [
"error",
"always"
],
"no-else-return": "warn",
"no-var": "error",
"prefer-const": "error",
"prefer-template": "error",
"radix": "error",
"array-bracket-newline": [
"error",
"consistent"
],
"array-bracket-spacing": [
"warn",
"always",
{
"singleValue": false,
"objectsInArrays": false,
"arraysInArrays": false
}
],
"array-element-newline": [
"warn",
{
"multiline": true,
"minItems": 3
}
],
"arrow-parens": [
"warn",
"as-needed"
],
"arrow-spacing": [
"error",
{
"before": true,
"after": true
}
],
"block-spacing": [
"error",
"always"
],
"brace-style": [
"error",
"1tbs"
],
"comma-dangle": [
"warn",
"always-multiline"
],
"comma-spacing": [
"error",
{
"before": false,
"after": true
}
],
"dot-location": [
"error",
"property"
],
"eol-last": [
"warn",
"always"
],
"func-call-spacing": [
"error",
"never"
],
"function-call-argument-newline": [
"error",
"never"
],
"function-paren-newline": [
"error",
"never"
],
"implicit-arrow-linebreak": [
"error",
"beside"
],
"indent": [
"error",
2,
{
"SwitchCase": 1,
"flatTernaryExpressions": true,
"offsetTernaryExpressions": true
}
],
"keyword-spacing": [
"warn",
{
"before": true,
"after": false
}
],
"lines-around-comment": [
"warn",
{
"afterBlockComment": true,
"beforeLineComment": true,
"ignorePattern": "*"
}
],
"multiline-ternary": [
"error",
"always"
],
"newline-per-chained-call": [
"error"
],
"no-extra-parens": [
"error",
"all"
],
"no-multi-spaces": [
"warn",
{
"ignoreEOLComments": true
}
],
"no-multiple-empty-lines": "warn",
"no-tabs": "error",
"no-trailing-spaces": "warn",
"no-whitespace-before-property": "error",
"object-curly-newline": [
"error",
{
"multiline": true
}
],
"object-curly-spacing": [
"error",
"always"
],
"object-property-newline": "error",
"operator-linebreak": [
"error",
"before"
],
"quotes": [
"error",
"single",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"rest-spread-spacing": [
"error",
"never"
],
"semi": [
"error",
"always"
],
"semi-spacing": "error",
"semi-style": [
"error",
"last"
],
"space-before-blocks": [
"error",
{
"functions": "never",
"keywords": "always",
"classes": "never"
}
],
"space-before-function-paren": [
"error",
{
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
}
],
"space-in-parens": [
"error",
"never"
],
"spaced-comment": [
"error",
"always",
{
"exceptions": [
// Allow lines to start with a second *, which
// basically allows jsdoc to work.
"*"
]
}
]
},
"globals": {
"define": "readonly",
"log": "readonly",
"Promise": "readonly"
}
}
Related
I'm using Storybook to develop a React component. The documentation of an SDK I'm importing in my app says to include a folder '.storybook/src/cards/myCard/xSDK' but not to bundle it.
I'm making the SDK call like this: importedSdkCall({SDKFolderPath: './xSDK'}). The folder is in the same directory as the component making the call.
I'm getting: 404 - http://localhost:6006/xSDK/x2.bundle.js
Storybook allows me to manipulate the generated webpack.config file. Here's the rules array from that file:
"rules": [
{
"test": {},
"use": [
{
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/builder-webpack4/node_modules/babel-loader/lib/index.js",
"options": {
"cacheDirectory": "/Users/christopheroppedal/Repos/experience-library/node_modules/.cache/storybook/babel",
"sourceType": "unambiguous",
"presets": [
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/preset-env/lib/index.js",
{
"shippedProposals": true,
"loose": true
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/#babel/preset-typescript/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/preset-react/lib/index.js",
{
"runtime": "automatic"
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/preset-flow/lib/index.js"
],
"plugins": [
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-shorthand-properties/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-block-scoping/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/#babel/plugin-proposal-decorators/lib/index.js",
{
"legacy": true
}
],
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-class-properties/lib/index.js",
{
"loose": true
}
],
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-private-methods/lib/index.js",
{
"loose": true
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-export-default-from/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-syntax-dynamic-import/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-object-rest-spread/lib/index.js",
{
"loose": true,
"useBuiltIns": true
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-classes/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-arrow-functions/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-parameters/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-destructuring/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-spread/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-for-of/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/babel-plugin-macros/dist/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/#babel/plugin-proposal-optional-chaining/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-nullish-coalescing-operator/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/babel-plugin-polyfill-corejs3/lib/index.js",
{
"method": "usage-global",
"absoluteImports": "/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/core-js/index.js",
"version": "3.15.2"
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/babel-plugin-add-react-displayname/index.js"
],
"overrides": [
{
"test": {},
"plugins": [
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/babel-plugin-react-docgen/lib/index.js",
{
"DOC_GEN_COLLECTION_NAME": "STORYBOOK_REACT_CLASSES"
}
]
]
}
]
}
}
],
"include": [
"/Users/christopheroppedal/Repos/experience-library"
],
"exclude": {}
},
{
"test": {},
"use": [
{
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/babel-loader/lib/index.js",
"options": {
"sourceType": "unambiguous",
"presets": [
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/preset-env/lib/index.js",
{
"shippedProposals": true,
"modules": false,
"loose": true,
"targets": "defaults"
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/preset-react/lib/index.js"
],
"plugins": [
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-shorthand-properties/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-block-scoping/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/#babel/plugin-proposal-decorators/lib/index.js",
{
"legacy": true
}
],
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-class-properties/lib/index.js",
{
"loose": true
}
],
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-private-methods/lib/index.js",
{
"loose": true
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-export-default-from/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-syntax-dynamic-import/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-object-rest-spread/lib/index.js",
{
"loose": true,
"useBuiltIns": true
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-classes/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-arrow-functions/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-parameters/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-destructuring/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-spread/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-for-of/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/babel-plugin-macros/dist/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/#babel/plugin-proposal-optional-chaining/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-nullish-coalescing-operator/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/babel-plugin-polyfill-corejs3/lib/index.js",
{
"method": "usage-global",
"absoluteImports": "/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/core-js/index.js",
"version": "3.15.2"
}
]
]
}
}
]
},
{
"test": {},
"use": [
{
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/raw-loader/dist/cjs.js"
}
]
},
{
"test": {},
"include": {},
"use": [
{
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/builder-webpack4/node_modules/babel-loader/lib/index.js",
"options": {
"presets": [
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/preset-env/lib/index.js",
{
"modules": "commonjs"
}
]
]
}
}
]
},
{
"test": {},
"use": [
{
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/builder-webpack4/node_modules/babel-loader/lib/index.js",
"options": {
"babelrc": false,
"configFile": false,
"cacheDirectory": "/Users/christopheroppedal/Repos/experience-library/node_modules/.cache/storybook/babel",
"sourceType": "unambiguous",
"presets": [
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/preset-env/lib/index.js",
{
"shippedProposals": true,
"loose": true
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/#babel/preset-typescript/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/preset-react/lib/index.js",
{
"runtime": "automatic"
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/preset-flow/lib/index.js"
],
"plugins": [
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-shorthand-properties/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-block-scoping/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/#babel/plugin-proposal-decorators/lib/index.js",
{
"legacy": true
}
],
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-class-properties/lib/index.js",
{
"loose": true
}
],
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-private-methods/lib/index.js",
{
"loose": true
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-export-default-from/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-syntax-dynamic-import/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-object-rest-spread/lib/index.js",
{
"loose": true,
"useBuiltIns": true
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-classes/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-arrow-functions/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-parameters/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-destructuring/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-spread/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-for-of/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/babel-plugin-macros/dist/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/#babel/plugin-proposal-optional-chaining/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-nullish-coalescing-operator/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/babel-plugin-polyfill-corejs3/lib/index.js",
{
"method": "usage-global",
"absoluteImports": "/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/core-js/index.js",
"version": "3.15.2"
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/babel-plugin-add-react-displayname/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-react-jsx/lib/index.js",
{
"pragma": "React.createElement",
"pragmaFrag": "React.Fragment"
}
]
],
"overrides": [
{
"test": {},
"plugins": [
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/babel-plugin-react-docgen/lib/index.js",
{
"DOC_GEN_COLLECTION_NAME": "STORYBOOK_REACT_CLASSES"
}
]
]
}
]
}
},
{
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/#mdx-js/loader/index.js",
"options": {
"compilers": [
null
],
"remarkPlugins": [
null,
null
]
}
}
]
},
{
"test": {},
"exclude": {},
"use": [
{
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/builder-webpack4/node_modules/babel-loader/lib/index.js",
"options": {
"babelrc": false,
"configFile": false,
"cacheDirectory": "/Users/christopheroppedal/Repos/experience-library/node_modules/.cache/storybook/babel",
"sourceType": "unambiguous",
"presets": [
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/preset-env/lib/index.js",
{
"shippedProposals": true,
"loose": true
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/#babel/preset-typescript/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/preset-react/lib/index.js",
{
"runtime": "automatic"
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/preset-flow/lib/index.js"
],
"plugins": [
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-shorthand-properties/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-block-scoping/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/#babel/plugin-proposal-decorators/lib/index.js",
{
"legacy": true
}
],
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-class-properties/lib/index.js",
{
"loose": true
}
],
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-private-methods/lib/index.js",
{
"loose": true
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-export-default-from/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-syntax-dynamic-import/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-object-rest-spread/lib/index.js",
{
"loose": true,
"useBuiltIns": true
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-classes/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-arrow-functions/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-parameters/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-destructuring/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-spread/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-for-of/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/babel-plugin-macros/dist/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/#babel/plugin-proposal-optional-chaining/lib/index.js",
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-proposal-nullish-coalescing-operator/lib/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/babel-plugin-polyfill-corejs3/lib/index.js",
{
"method": "usage-global",
"absoluteImports": "/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/core-common/node_modules/core-js/index.js",
"version": "3.15.2"
}
],
"/Users/christopheroppedal/Repos/experience-library/node_modules/babel-plugin-add-react-displayname/index.js",
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/#babel/plugin-transform-react-jsx/lib/index.js",
{
"pragma": "React.createElement",
"pragmaFrag": "React.Fragment"
}
]
],
"overrides": [
{
"test": {},
"plugins": [
[
"/Users/christopheroppedal/Repos/experience-library/node_modules/babel-plugin-react-docgen/lib/index.js",
{
"DOC_GEN_COLLECTION_NAME": "STORYBOOK_REACT_CLASSES"
}
]
]
}
]
}
},
{
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/#mdx-js/loader/index.js",
"options": {
"remarkPlugins": [
null,
null
]
}
}
]
},
{
"test": {},
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/source-loader/dist/cjs/index.js",
"options": {
"injectStoryParameters": true,
"inspectLocalDependencies": true
},
"enforce": "pre"
},
{
"test": {},
"sideEffects": true,
"use": [
"/Users/christopheroppedal/Repos/experience-library/node_modules/style-loader/dist/cjs.js",
{
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/css-loader/dist/cjs.js",
"options": {
"importLoaders": 1
}
},
{
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/#storybook/builder-webpack4/node_modules/postcss-loader/dist/cjs.js",
"options": {
"postcssOptions": {
"config": false,
"plugins": [
null,
null
]
}
}
}
]
},
{
"test": {},
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/file-loader/dist/cjs.js",
"options": {
"esModule": false,
"name": "static/media/[path][name].[ext]"
}
},
{
"test": {},
"loader": "/Users/christopheroppedal/Repos/experience-library/node_modules/url-loader/dist/cjs.js",
"options": {
"limit": 10000,
"name": "static/media/[path][name].[ext]"
}
}
] ```
I solved this by changing to a create-react-app project and moving the bundled SDK into the /public directory.
i don't get why ngrx pop this error while i'm trying to send to my api a simple object, could you give me some advice about ngrx and the reason why it refuse to serialize my object ?
I tried to put strictActionSerializability to false , no error but no object sent to my api...
Error :
Error: Detected unserializable action at "createdPath"
How i call my action :
this.storePath.dispatch(PathActions.createPath({ createdPath }));
In actions.ts file :
export const createPath = createAction('[BOT/GROUP] CREATE PATH', props<{ createdPath: Path }>());
And my effect :
createPath$ = createEffect(() =>
this.actions$.pipe(
ofType(PathActions.createPath),
map(action => action.createdPath),
exhaustMap((createdPath: Path) =>
this.pathService.createPath(createdPath).pipe(
map(createdPath => PathActions.createPathSuccess({ createdPath })),
catchError(error => of(PathActions.createPathFailure({ error }))))
)
)
);
My object sent as JSON :
{
"monsterLevel": [],
"monsterQuantity": [],
"monsterCapture": [],
"pathAction": [
{
"actions": [
{
"order": 1,
"fightAction": {
"isAlone": false
}
},
{
"order": 2,
"moveAction": {
"direction": [
"Right",
"Bottom"
],
"toGoBank": false,
"toBackBank": false
}
}
],
"mapPos": "-14;-53"
},
{
"actions": [
{
"order": 1,
"fightAction": {
"isAlone": false
}
},
{
"order": 2,
"moveAction": {
"direction": [
"Top",
"Right"
],
"toGoBank": false,
"toBackBank": false
}
}
],
"mapPos": "-14;-52"
},
{
"actions": [
{
"order": 1,
"fightAction": {
"isAlone": false
}
},
{
"order": 2,
"moveAction": {
"direction": [
"Top",
"Left"
],
"toGoBank": false,
"toBackBank": false
}
}
],
"mapPos": "-13;-52"
},
{
"actions": [
{
"order": 1,
"fightAction": {
"isAlone": false
}
},
{
"order": 2,
"moveAction": {
"direction": [
"Left",
"Bottom"
],
"toGoBank": false,
"toBackBank": false
}
}
],
"mapPos": "-13;-53"
},
{
"actions": [
{
"order": 1,
"moveAction": {
"direction": [
"Bottom"
],
"toGoBank": true,
"toBackBank": false
}
}
],
"mapPos": "-14;-51"
},
{
"actions": [
{
"order": 1,
"moveAction": {
"direction": [
"Bottom"
],
"toGoBank": true,
"toBackBank": false
}
}
],
"mapPos": "-14;-50"
},
{
"actions": [
{
"order": 1,
"moveAction": {
"direction": [
"Bottom"
],
"toGoBank": true,
"toBackBank": false
}
}
],
"mapPos": "-14;-49"
},
{
"actions": [
{
"order": 1,
"moveAction": {
"direction": [
"Bottom"
],
"toGoBank": true,
"toBackBank": false
}
}
],
"mapPos": "-14;-48"
},
{
"actions": [
{
"order": 1,
"moveAction": {
"cellId": 150,
"toGoBank": true,
"toBackBank": false
}
},
{
"order": 2,
"zaapAction": {
"destination": "-32,-58",
"zaapId": 1,
"toBackBank": false,
"toGoBank": true
}
}
],
"mapPos": "-14;-47"
}
],
"name": "feef",
"type": 0,
"monsterQuantityMin": 0,
"monsterQuantityMax": 8,
"groupLevelMin": 0,
"groupLevelMax": 999,
"maxPod": 51,
"leaderBank": true
}
Class used:
export class Path {
name: string;
type: number; /* 0 fight , 1 gather */
maxPod: number=80;
monsterQuantityMin: number =0;
monsterQuantityMax: number =8;
groupLevelMin: number =0;
groupLevelMax: number=9999;
isCapture: boolean =false;
leaderBank: boolean = false;
captureItem: number;
monsterLevel?: SpecificMonsterLevel[];
monsterQuantity?: SpecificMonsterQuantity[];
monsterCapture?: CaptureMonsterQuantity[];
pathAction: PathAction[];
}
have a good day, and thanks for your help !
For a pure data class object you can use
JSON.parse(JSON.stringify(product))
Otherwise, I suggest adding a toJSON() serialization method (which is automatically used by JSON.stringify)
public class Foo{
private _bar:string;
constructor(){ this._bar='Baz'; }
get bar():string{return this._bar}
toJSON() {
return {bar: _bar};
}
static fromJSON(json) {
...
}
}
Reference - Angular 2 (or 4) object serialization
#Andrew Allen resolved my issue by stringify and re parse my object :
this.storePath.dispatch(PathActions.createPath({ createdPath: JSON.parse(JSON.stringify(createdPath)) }));
I am using Visual Studio 2017 and eslint 2.0 (I assume), which is built into Visual Studio.
Eslint works fine except when the JS file contains ES6 features such as async and const. In this case, the Error List window in Visual Studio remains empty and there are no eslint messages displayed. It seems that eslint just fails silently when it stumbles upon a file with those keywords.
Eslint must support ES6 and I also enabled ES6 in the .eslintrc file.
I am not sure how to see the output from eslint to see if there's any error, because Visual Studio runs it in the background.
How do I run eslint in Visual Studio when my JS file contains ES6 features?
Here's my .eslintrc:
{
"parserOptions": {
"ecmaVersion": 6
},
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
},
"env": {
"browser": false,
"es6": true,
"node": true
},
"plugins": [
"standard"
],
"globals": {
"document": false,
"navigator": false,
"window": false
},
"rules": {
"accessor-pairs": 2,
"arrow-spacing": [
2,
{
"before": true,
"after": true
}
],
"block-spacing": [ 2, "always" ],
"brace-style": [
2,
"1tbs",
{ "allowSingleLine": true }
],
"comma-dangle": [ 2, "always-multiline" ],
"comma-spacing": [
2,
{
"before": false,
"after": true
}
],
"comma-style": [ 2, "last" ],
"constructor-super": 2,
"curly": [ 2, "multi-line" ],
"dot-location": [ 2, "property" ],
"eol-last": 0,
"eqeqeq": [ 2, "allow-null" ],
"generator-star-spacing": [
2,
{
"before": true,
"after": true
}
],
"handle-callback-err": [ 2, "^(err|error)$" ],
"indent": [
2,
2,
{ "SwitchCase": 1 }
],
"key-spacing": [
2,
{
"beforeColon": false,
"afterColon": true
}
],
"keyword-spacing": [
2,
{
"before": true,
"after": true
}
],
"new-cap": [
2,
{
"newIsCap": true,
"capIsNew": false
}
],
"new-parens": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-class-assign": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-labels": [
2,
{
"allowLoop": false,
"allowSwitch": true
}
],
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": [ 2, "functions" ],
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inner-declarations": [ 2, "functions" ],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-lone-blocks": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [
2,
{ "max": 1 }
],
"no-native-reassign": 2,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-proto": 2,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": [
2,
{ "defaultAssignment": false }
],
"no-unreachable": 2,
"no-unused-vars": [
2,
{
"vars": "all",
"args": "none"
}
],
"no-useless-call": 2,
"no-with": 2,
"one-var": [
2,
{ "initialized": "never" }
],
"operator-linebreak": [
2,
"after",
{
"overrides": {
"?": "before",
":": "before"
}
}
],
"padded-blocks": [ 2, "never" ],
"quotes": [ 2, "single" ],
"radix": 2,
"semi": [ 2, "always" ],
"semi-spacing": [
2,
{
"before": false,
"after": true
}
],
"space-before-blocks": [ 2, "always" ],
"space-before-function-paren": [ 2, "always" ],
"space-in-parens": [ 2, "never" ],
"space-infix-ops": 2,
"space-unary-ops": [
2,
{
"words": true,
"nonwords": false
}
],
"spaced-comment": [
2,
"always",
{ "markers": [ "global", "globals", "eslint", "eslint-disable", "*package", "!", "," ] }
],
"use-isnan": 2,
"valid-typeof": 2,
"wrap-iife": [ 2, "any" ],
"yoda": [ 2, "never" ],
"standard/object-curly-even-spacing": [ 2, "either" ],
"standard/array-bracket-even-spacing": [ 2, "either" ],
"standard/computed-property-even-spacing": [ 2, "even" ]
}
}
I'm using a module to parse apache configuration files into json
https://github.com/tellnes/node-apacheconf
it works just perfect . when I perform JSON.stringify() the resulted JSON object doesn't contain comments .
output of console.log(config) :
{ ThreadsPerChild: [ '250', comments: [ [Array] ] ],
MaxRequestsPerChild: [ '0', comments: [ [] ] ],
Listen: [ '80', comments: [ [] ] ],
ServerRoot: [ '"/www/Apache22"', comments: [ [] ] ],
DocumentRoot: [ '"/THDL/thdl-site"', comments: [ [] ] ],
ServerName: [ 'localhost:80', comments: [ [Array] ] ],
ServerAdmin: [ 'admin#localhost', comments: [ [] ] ],
ErrorLog: [ 'logs/error.log', comments: [ [] ] ],
LogLevel: [ 'error', comments: [ [] ] ],
LoadModule:
[ 'alias_module modules/mod_alias.so',
'authz_host_module modules/mod_authz_host.so',
'autoindex_module modules/mod_autoindex.so',
'dir_module modules/mod_dir.so',
'log_config_module modules/mod_log_config.so',
'mime_module modules/mod_mime.so',
'rewrite_module modules/mod_rewrite.so',
'setenvif_module modules/mod_setenvif.so',
'php5_module "C:/www/php5/php5apache2.dll"',
comments: [ [Array], [Array], [Array], [Array], [Array], [], [Array], [], [] ] ],
IfDefine:
[ { '$args': 'SSL', LoadModule: [Array] },
comments: [ [Array] ] ],
DefaultType: [ 'text/plain', comments: [ [] ] ],
IfModule:
[ { '$args': 'dir_module', DirectoryIndex: [Array] },
{ '$args': 'mime_module',
TypesConfig: [Array],
AddType: [Array] },
{ '$args': '!php5_module', IfModule: [Array] },
{ '$args': 'php5_module', Location: [Array] },
{ '$args': 'ssl_module',
Include: [Array],
SSLRandomSeed: [Array] },
{ '$args': 'mod_alias.c', Alias: [Array] },
comments: [ [], [], [Array], [], [], [Array] ] ],
IndexIgnore: [ '.htaccess', comments: [ [] ] ],
FilesMatch:
[ { '$args': '^.ht', Order: [Array], Deny: [Array] },
comments: [ [] ] ],
Redirect: [ '/thdl external link: http://localhost', comments: [ [] ] ],
Directory:
[ { '$args': '/',
Options: [Array],
AllowOverride: [Array],
Order: [Array],
Allow: [Array],
Satisfy: [Array] },
{ '$args': '/THDL/thdl-site',
Options: [Array],
AllowOverride: [Array],
Order: [Array],
Allow: [Array] },
{ '$args': 'C:/www/phpMyAdmin',
Options: [Array],
AllowOverride: [Array],
order: [Array],
deny: [Array],
allow: [Array] },
comments: [ [], [Array], [] ] ],
Include:
[ 'conf/extra/httpd-autoindex.conf',
'conf/extra/httpd-languages.conf',
'conf/extra/httpd-info.conf',
'conf/extra/httpd-manual.conf',
'conf/extra/httpd-default.conf',
'conf/Suite-extra/components.conf',
comments: [ [Array], [Array], [Array], [Array], [Array], [Array] ] ],
LoadFile: [ '"C:/www/php5/php5ts.dll"', comments: [ [Array] ] ] }
output of console.log(JSON.stringify(config)) :
{
"ThreadsPerChild": [
"250"
],
"MaxRequestsPerChild": [
"0"
],
"Listen": [
"80"
],
"ServerRoot": [
"\"/www/Apache22\""
],
"DocumentRoot": [
"\"/THDL/thdl-site\""
],
"ServerName": [
"localhost:80"
],
"ServerAdmin": [
"admin#localhost"
],
"ErrorLog": [
"logs/error.log"
],
"LogLevel": [
"error"
],
"LoadModule": [
"alias_module modules/mod_alias.so",
"authz_host_module modules/mod_authz_host.so",
"autoindex_module modules/mod_autoindex.so",
"dir_module modules/mod_dir.so",
"log_config_module modules/mod_log_config.so",
"mime_module modules/mod_mime.so",
"rewrite_module modules/mod_rewrite.so",
"setenvif_module modules/mod_setenvif.so",
"php5_module \"C:/www/php5/php5apache2.dll\""
],
"IfDefine": [
{
"$args": "SSL",
"LoadModule": [
"ssl_module modules/mod_ssl.so"
]
}
],
"DefaultType": [
"text/plain"
],
"IfModule": [
{
"$args": "dir_module",
"DirectoryIndex": [
"index.html index.php index.aspx"
]
},
{
"$args": "mime_module",
"TypesConfig": [
"conf/mime.types"
],
"AddType": [
"application/x-compress .Z",
"application/x-gzip .gz .tgz"
]
},
{
"$args": "!php5_module",
"IfModule": [
{
"$args": "!php4_module",
"Location": [
{
"$args": "/",
"FilesMatch": [
{
"$args": ".php[45]?$",
"Order": [
"allow,deny"
],
"Deny": [
"from all"
]
}
]
}
]
}
]
},
{
"$args": "php5_module",
"Location": [
{
"$args": "/",
"AddType": [
"text/html .php .phps"
],
"AddHandler": [
"application/x-httpd-php .php",
"application/x-httpd-php-source .phps"
]
}
]
},
{
"$args": "ssl_module",
"Include": [
"conf/extra/httpd-ssl.conf"
],
"SSLRandomSeed": [
"startup builtin",
"connect builtin"
]
},
{
"$args": "mod_alias.c",
"Alias": [
"/phpMyAdmin \"C:/www/phpMyAdmin\""
]
}
],
"IndexIgnore": [
".htaccess"
],
"FilesMatch": [
{
"$args": "^.ht",
"Order": [
"allow,deny"
],
"Deny": [
"from all"
]
}
],
"Redirect": [
"/thdl external link: http://localhost"
],
"Directory": [
{
"$args": "/",
"Options": [
"FollowSymLinks"
],
"AllowOverride": [
"all"
],
"Order": [
"deny,allow"
],
"Allow": [
"from all"
],
"Satisfy": [
"all"
]
},
{
"$args": "/THDL/thdl-site",
"Options": [
"Indexes FollowSymLinks"
],
"AllowOverride": [
"all"
],
"Order": [
"allow,deny"
],
"Allow": [
"from all"
]
},
{
"$args": "C:/www/phpMyAdmin",
"Options": [
"None"
],
"AllowOverride": [
"None"
],
"order": [
"deny,allow"
],
"deny": [
"from all"
],
"allow": [
"from 127.0.0.1"
]
}
],
"Include": [
"conf/extra/httpd-autoindex.conf",
"conf/extra/httpd-languages.conf",
"conf/extra/httpd-info.conf",
"conf/extra/httpd-manual.conf",
"conf/extra/httpd-default.conf",
"conf/Suite-extra/components.conf"
],
"LoadFile": [
"\"C:/www/php5/php5ts.dll\""
]
}
comments field is completely ignored in the whole structure . how can I prevent this from happening .
I don't think you can use keys like that inside arrays.
For example, try changing:
DefaultType: [ 'text/plain', comments: [ [] ] ],
to:
DefaultType: { type: 'text/plain', comments: [ [] ] },
Objects contain keys with values: { key1: value1, key2: value2 }
Arrays contain comma separated values: [ value1, value2 ]
Objects can also contain values that are arrays of values: { key1: [ value1, value2 ] }
or multi-dimensional: { key1: [ value1, [ value2, value3 ] ] }
It looks like a problem with the structure of your config object. I recommend changing it to match my examples.
I am trying to use ESLint to enforce some flow rules to the linting procedure but ESLint only reports non-flow errors.
I used this guide: eslint-plugin-flowtype
My .eslintrc.json file is the following :
{
"extends": ["airbnb-base", "plugin:flowtype/recommended"],
"parser": "babel-eslint",
"plugins": [
"import",
"flowtype"
],
"rules": {
"flowtype/boolean-style": [
2,
"boolean"
],
"flowtype/define-flow-type": 1,
"flowtype/delimiter-dangle": [
2,
"never"
],
"flowtype/generic-spacing": [
2,
"never"
],
"flowtype/no-primitive-constructor-types": 2,
"flowtype/no-weak-types": 2,
"flowtype/object-type-delimiter": [
2,
"comma"
],
"flowtype/require-parameter-type": 2,
"flowtype/require-return-type": [
2,
"always",
{
"annotateUndefined": "never"
}
],
"flowtype/require-valid-file-annotation": 2,
"flowtype/semi": [
2,
"always"
],
"flowtype/space-after-type-colon": [
2,
"always"
],
"flowtype/space-before-generic-bracket": [
2,
"never"
],
"flowtype/space-before-type-colon": [
2,
"never"
],
"flowtype/type-id-match": [
2,
"^([A-Z][a-z0-9]+)+Type$"
],
"flowtype/union-intersection-spacing": [
2,
"always"
],
"flowtype/use-flow-type": 1,
"flowtype/valid-syntax": 1
},
"settings": {
"flowtype": {
"onlyFilesWithFlowAnnotation": false
}
}
}