Tslint: JSX elements with no children must be self closing [Error] - html

So I've been searching for a solution to this issue. My solution will not build via the command npm run build as I have the error:
JSX elements with no children must be self-closing.
There is a similar issue here with no accepted (or working) answers: JSX elements with no children must be self-closing
The associated Typescript/HTML is of the format:
class ExampleClass {
render() {
return <div>
<div>
<div>Content 1</div>
<div>Content 2</div>
<div>Content 3</div>
</div>
</div>;
}
}
export default ExampleClass;
The "error" occurs on line 5 which is:
<div>Content 1</div>
I'm using Tslint and have a number of the features of Tslint already changed / working in the file tslint.json.
See the tslint.json file as it currently stands:
{
"extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
"linterOptions": {
"exclude": [
"gulpfile.js",
"bin/**",
"wwwroot/**",
"config/**/*.js",
"node_modules/**"
]
},
"rules": {
"prefer-const": false,
"triple-equals": false,
"jsx-no-lambda": false,
"object-literal-shorthand": false,
"no-shadowed-variable": false,
"ban-types": false,
"one-variable-per-declaration": false,
"callable-types": false,
"quotemark": [ false, "single", "jsx-double" ],
"indent": [ true, "spaces", 2 ],
"interface-name": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"no-consecutive-blank-lines": false,
"comment-format": false,
"no-trailing-whitespace": false,
"one-line": false,
"max-classes-per-file": false,
"jsx-boolean-value": false,
"no-empty-interface": false,
"variable-name": [ true, "allow-pascal-case", "allow-snake-case" ],
"no-console": false,
"interface-over-type-literal": false
}
}
Here are the various things I've tried (consecutively, not all at once) - with no success:
"prefer-const": [
true,
{ "destructuring": "all" }
],
"react/self-closing-comp": "off",
"react/self-closing-comp": false,
"no-trailing-whitespace": false
The rules for Tslint can be found here: TSLint core rules
What I'm not looking to do is:
Completely disable TSLint
Modify my HTML structure unless totally necessary
What I'm looking for is the correct Tslint rule to use to suppress this error.
E.g. "react/self-closing-comp": false.
Hopefully someone out there has seen this before & can give me a hand!
Many thanks!

According to the npmjs.com as of the 20/01/2020:
TSLint has been deprecated in favor of ESLint. Please see https://github.com/palantir/tslint-react/issues/210 for more information.
You can configure your existing TSLint solution to use the new rules from ESLint, this is done like so:
According to npmjs.com, install ESLint with the npm command: npm install eslint --save-dev
According to npmjs.com, allow the ESLint rules by running the following command: npm install --save-dev tslint-eslint-rules
Modify your tslint.json file by adding an extends property, like so: "extends": [ "tslint-eslint-rules"]
A good number of relevant ESLint rules are found here: ESLint Rules - npmjs.com and here ESLint Rules - eslint.org
The relevant rule to fix the error:
JSX elements with no children must be self-closing.
was this:
"jsx-self-close": false
My final tslint.json file looked like this:
{
"extends": [ "tslint-eslint-rules", "tslint:latest", "tslint-react", "tslint-config-prettier" ],
"linterOptions": {
"exclude": [
"gulpfile.js",
"bin/**",
"wwwroot/**",
"config/**/*.js",
"node_modules/**"
]
},
"rules": {
"jsx-self-close": false,
"jsx-wrap-multiline": false,
"no-constant-condition": true,
"no-unused-expression": false,
"no-unused-variable": false,
"no-string-throw": false,
"prefer-const": false,
"triple-equals": false,
"jsx-no-lambda": false,
"object-literal-shorthand": false,
"no-shadowed-variable": false,
"ban-types": false,
"one-variable-per-declaration": false,
"callable-types": false,
"quotemark": [ false, "single", "jsx-double" ],
"indent": [ true, "spaces", 2 ],
"interface-name": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"no-consecutive-blank-lines": false,
"comment-format": false,
"no-trailing-whitespace": false,
"one-line": false,
"max-classes-per-file": false,
"jsx-boolean-value": false,
"no-empty-interface": false,
"variable-name": false,
"no-console": false,
"interface-over-type-literal": false,
"no-conditional-assignment": false,
"only-arrow-functions": false,
"no-var-keyword": false,
"no-empty": false,
"no-submodule-imports": false,
"no-duplicate-imports": false,
"no-useless-rename": false,
"no-implicit-dependencies": false,
"no-return-await": false,
"no-object-literal-type-assertion": false,
"prefer-object-spread": false,
"prefer-conditional-expression": false,
"jsdoc-format": false,
"prefer-for-of": false,
"radix": false
}
}
Hopefully this saves someone some time!

Related

What is best way to go about replacing 'deployUrl' in angular.json for v13?

I'm currently in the process of upgrading my app from v12 to v13 and noticed this warning pop up:
Option "deployUrl" is deprecated: Use "baseHref" option, "APP_BASE_HREF" DI token or a combination of both instead. For more information, see https://angular.io/guide/deployment#the-deploy-url.
After digging into it a little more, none of the 'baseHref' or APP_BASE_REF options really work for my setup so I'm wondering if I'm using them incorrectly or if there isn't a good way to go about replacing it
Here's a snippet of the app config from angular.json:
"dashboard": {
"projectType": "application",
"root": "apps/dashboard",
"sourceRoot": "apps/dashboard/src",
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"allowedCommonJsDependencies": [],
"outputPath": "../dist/dashboard/",
"deployUrl": "/dist/dashboard/",
"index": "apps/dashboard/src/index.html",
"main": "apps/dashboard/src/main.ts",
"tsConfig": "apps/dashboard/tsconfig.app.json",
"polyfills": "apps/dashboard/src/polyfills.ts",
"styles": [
"apps/dashboard/src/styles.scss"
],
"scripts": [],
"stylePreprocessorOptions": {
"includePaths": [
"libs/assets/styles"
]
},
"aot": false,
"vendorChunk": true,
"extractLicenses": false,
"buildOptimizer": false,
"sourceMap": true,
"optimization": false,
"namedChunks": true
},
"configurations": {
"production": {
"aot": true,
"buildOptimizer": true,
"extractLicenses": true,
"fileReplacements": [
{
"replace": "apps/dashboard/src/environments/environment.ts",
"with": "apps/dashboard/src/environments/environment.prod.ts"
}
],
"namedChunks": false,
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"vendorChunk": false
},
"es5": {
"tsConfig": "apps/dashboard/tsconfig.es5.json"
}
},
"defaultConfiguration": ""
}
}
}
Snippet of routing file:
export const DashboardRoutes: Routes = [
{ path: '', pathMatch: 'full', redirectTo: '/dashboard' },
{
path: 'dashboard',
data: {
label: 'Dashboard',
appBase: true
},
children: [
// this is a child so we can load the component in same router-outlet
{
path: '',
loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule),
data: {
authorizedRoles: ['member'],
}
},
// ...other children
]
}
]
I've tried changing deployUrl to baseHref and that works, kind of - It changes the main page from localhost/dashboard to localhost/dist/dashboard/dashboard (obviously not right) and just putting an empty string or "/" doesn't load the app correctly (looks at dist/ vs dist/dashboard like it should)
Worth noting that my index.html does use <base href="/" /> and APP_BASE_HREF is not overridden in the app module providers
Ended up finding something to replace this with:
Replaced "deployUrl" with "baseHref" in angular.json
Added the APP_BASE_HREF override in app.module
i.e { provide: APP_BASE_HREF, useValue: '/' }
Replaced any hrefs in index.html that referenced the dist (output) folder
e.g replaced 'dist/assets/{some_asset}' with '../assets/{some_asset'}'
index.html still uses <base href="/">
This is a problem with Angular 13+
Found a solution here:
https://github.com/angular/angular-cli/issues/22113#issuecomment-1004279867
You should put following code in your main.ts file:
declare var __webpack_public_path__: string;
__webpack_public_path__ = 'valueFormerlyAssignedUsing_deployUrl';
Replace valueFormerlyAssignedUsing_deployUrl with your path to folder containing chunks.

VS Code format splitting comma-separated items in JSON file

VS Code wants to split comma separated arguments into separate lines. I would prefer it not do this. It only happens on one machine and I can't discover the setting that makes this happen.
As an example, consider this text in settings.json
"args": [
"-q", "query",
"-a", "answer"
]
I have format-on-save turned on, and every time I save the file, I get this
"args": [
"-q",
"query",
"-a",
"answer"
]
I would prefer that it leave these alone, like on all of my other machines. Please note that I do not want to turn off auto-format, I just want this wrapping behavior to stop.
[New Info]
I copied the User settings ~/Library/Application Support/Code/User/settings.json from the machine that did not have the wrapping issues to the machine that did have the issues. I'm not sure which setting it was, but that fixed the problem. I'd still love to know which setting caused this behavior. Both files are below.
Wrapping Issues Settings
{
"telemetry.enableTelemetry": false,
"editor.minimap.enabled": false,
"files.autoSave": "afterDelay",
"workbench.sideBar.location": "left",
//"editor.wordWrap": "bounded",
"editor.wordWrapColumn": 132,
"editor.wrappingIndent": "deepIndent",
"go.formatTool": "goimports",
"go.liveErrors": {
"enabled": true,
"delay": 500
},
"go.vetOnSave": "workspace",
"go.gocodeAutoBuild": true,
"git.enableCommitSigning": true,
"go.autocompleteUnimportedPackages": true,
"git.autofetch": true,
"git.confirmSync": false,
"editor.formatOnPaste": true,
"editor.formatOnType": true,
"editor.formatOnSave": true,
"python.testing.unittestEnabled": true,
"python.venvPath": "~/develop/virtualenv",
"python.linting.pep8Enabled": true,
"editor.detectIndentation": false,
"search.quickOpen.includeSymbols": true,
"workbench.colorTheme": "Default Light+",
}
No Wrapping Issues Settings
{
"telemetry.enableTelemetry": false,
"window.zoomLevel": 0,
"files.autoSave": "afterDelay",
"editor.fontSize": 14,
"editor.minimap.enabled": false,
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
},
"editor.wordWrap": "on",
"editor.wrappingIndent": "deepIndent",
"editor.wordWrapColumn": 132,
"go.autocompleteUnimportedPackages": true,
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"go.gocodeAutoBuild": true,
"debug.enableAllHovers": true,
"debug.inlineValues": true,
"git.enableCommitSigning": true,
"python.jediEnabled": false,
"[python]": {
},
"python.testing.unittestEnabled": true,
"git.autofetch": true,
"python.venvPath": "~/develop/virtualenv",
"python.linting.pep8Enabled": true,
"editor.detectIndentation": false,
"editor.formatOnPaste": true,
"window.openFilesInNewWindow": "on",
}
Combined settings with duplicates removed
paul-> cat settings.json.old.json settings.json |sort|uniq
"**/.classpath": true,
"**/.factorypath": true
"**/.project": true,
"**/.settings": true,
"delay": 500
"enabled": true,
"[python]": {
"debug.enableAllHovers": true,
"debug.inlineValues": true,
"editor.detectIndentation": false,
"editor.fontSize": 14,
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.minimap.enabled": false,
"editor.suggestSelection": "first",
"editor.wordWrap": "on",
"editor.wordWrapColumn": 132,
"editor.wrappingIndent": "deepIndent",
"files.autoSave": "afterDelay",
"files.exclude": {
"git.autofetch": true,
"git.confirmSync": false,
"git.enableCommitSigning": true,
"go.autocompleteUnimportedPackages": true,
"go.formatTool": "goimports",
"go.gocodeAutoBuild": true,
"go.liveErrors": {
"go.vetOnSave": "workspace",
"python.jediEnabled": false,
"python.linting.pep8Enabled": true,
"python.testing.unittestEnabled": true,
"python.venvPath": "~/develop/virtualenv",
"search.quickOpen.includeSymbols": true,
"telemetry.enableTelemetry": false,
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"window.openFilesInNewWindow": "on",
"window.zoomLevel": 0,
"workbench.colorTheme": "Default Light+",
"workbench.sideBar.location": "left",
//"editor.wordWrap": "bounded",
},
{
}
}{
See https://stackoverflow.com/a/73180702/836330 for a similar case.
Enable this setting: JSON > Format: Keep Lines
With that setting enabled - it is coming in v1.70
"args": [
"-q", "query",
"-a", "answer"
]
will stay exactly that way. Lines with multiple values or multiple key/value pairs will be "kept" as is.

ctrl+n doesn't open new tab in Sublime Text 3

Well it start working for a while when I change the color theme, but then fails again.
My custom settings:
{
"color_scheme": "Packages/Material Theme/schemes/Material-Theme.tmTheme",
"font_size": 10,
"ignored_packages":
[
"Theme - SoDaReloaded",
"Vintage",
"Web Inspector"
],
"material_theme_accent_cyan": true,
"material_theme_arrow_folders": true,
"material_theme_bright_scrollbars": true,
"material_theme_compact_panel": true,
"material_theme_compact_sidebar": true,
"material_theme_panel_separator": true,
"material_theme_small_statusbar": true,
"material_theme_small_tab": true,
"material_theme_tabs_autowidth": true,
"material_theme_tabs_separator": true,
"material_theme_tree_headings": true,
"theme": "Material-Theme.sublime-theme"
}
Windows 7
Problem solved. Just removed one package that somehow overrides the key bindings.

Gulp cannot parse .hintrc file

When running this Gulp task
var gulp = require('gulp'),
util = require('gulp-util'), // For logging
print = require('gulp-print'), // For logging
jshint = require('gulp-jshint');
gulp.task('analyse', function () {
log('Analyzing source with JSHint')
gulp.src(paths.jsContent)
.pipe(print())
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish', { verbose: true }))
.pipe(jshint.reporter('fail'));
});
I get this output:
[14:43:26] Starting 'analyse'...
[14:43:26] Analyzing source with JSHint
[14:43:26] Finished 'analyse' after 32 ms
[gulp] Scripts\main.js
ERROR: Can't parse config file: C:\MyProject\src\MyProject.jshintrc
Error:SyntaxError: Unexpected token
The Gulp file I use is from https://raw.githubusercontent.com/johnpapa/pluralsight-gulp/master/.jshintrc and looks like:
{
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"es3": false,
"forin": true,
"freeze": true,
"immed": true,
"indent": 4,
"latedef": "nofunc",
"newcap": true,
"noarg": true,
"noempty": true,
"nonbsp": true,
"nonew": true,
"plusplus": false,
"quotmark": "single",
"undef": true,
"unused": false,
"strict": false,
"maxparams": 10,
"maxdepth": 5,
"maxstatements": 40,
"maxcomplexity": 8,
"maxlen": 120,
"asi": false,
"boss": false,
"debug": false,
"eqnull": true,
"esnext": false,
"evil": false,
"expr": false,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": false,
"laxcomma": false,
"loopfunc": true,
"maxerr": 50,
"moz": false,
"multistr": false,
"notypeof": false,
"proto": false,
"scripturl": false,
"shadow": false,
"sub": true,
"supernew": false,
"validthis": false,
"noyield": false,
"browser": true,
"node": true,
"globals": {
"angular": false
}
}
Can this be solved?
Just replace your .jshintrc file with the original from John's repo and you will be fine.

karma config - exclude src subfolder

i have a problem with the glob syntax in the karma files config. Let's assume this folder
structure:
-js
-one
-subone
-two
-special
-four
Now, I want all files/folders within js to be served and included EXCEPT the special folder should only be served but NOT included.
I tried this config:
files: [
{pattern: 'js/**/!(special)/*.js', watched: false, served: true, included: true},
{pattern: 'js/special/**/*.js', watched: false, served: true, included: false}
],
I also tried this config, because I found something seemingly similar on the web:
files: [
{pattern: 'js/*[!special]/*.js', watched: false, served: true, included: true},
{pattern: 'js/special/**/*.js', watched: false, served: true, included: false}
],
but they don't work. The result currently always is: The special folder with its contents is
served, but no other js file/folder.
Update
I now directly played with node.js minimatch lib and tried these pattern:
files: [
{pattern: 'js/!(special)/**/*.js', watched: false, served: true, included: true},
{pattern: 'js/special/**/*.js', watched: false, served: true, included: false}
],
This works in minimatch, but not in Karma. Why not?
--end update--
Can someone help me coming up with the correct rule? Thanks.
Found the problem. In order to really reach all files I needed to have an additional rule:
{pattern: 'js/*.js', watched: false, served: true, included: true},
Quite obvious, if I look at it now, just didn't see it in the first place.