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.
Related
I'm building a node module that builds reports using html-pdf.
I got an html file in which I'm trying to access images in ways like:
These images are under src/templates/ and bundled as dist/templates.
This should be consumed from a nextjs application.
What I noticed is that the absolute path worked for me, I mean, if I print it points to the image.
For full path: i'm doing path.join(__dirname, "templates", "header-footer.png")
tsconfig.json
{
"include": ["src", "types"],
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"lib": ["dom", "esnext"],
"esModuleInterop": true,
"importHelpers": true,
"sourceMap": true,
"declaration": true,
"moduleResolution": "node",
"skipLibCheck": true,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true
}
}
Any clues about this?
I've tried also to use a URL relative to the root directory of the site su
<img src="/templates/header-footer.png" />
So, after burning my brain for some days, i found that i have to define a basepath within the lib options as this
var options = {
format: "A4",
base: "file:///" + __dirname + "/",
localUrlAccess: true, // set this to true to enable local file access
};
and in my html refer to he files as:
src="templates/header-logo.png"
This works.
I have problem importing json files into typescript. I have configured tsconfig.json according to the convention, but it still does not work in the environment.ts file, however in the environment.prod.ts file, the import works perfectly
environment.ts
import { domain, clientId, audience, serverUrl } from '../../auth_config.json';
export const environment = {
production: false,
auth: {
domain,
clientId,
redirectUri: window.location.origin,
audience,
},
dev: {
serverUrl,
},
};
ERROR -->
Cannot find module '../../auth_config.json'. Consider using '--resolveJsonModule' to import module with '.json' extensionts(2732)
environment.prod.ts
import { domain, clientId, audience, serverUrl } from '../../auth_config.json';
export const environment = {
production: true,
auth: {
domain,
clientId,
redirectUri: window.location.origin,
audience,
},
dev: {
serverUrl,
},
};
Its work ok.
My tsconfig.json
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": [],
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"strict": true,
"resolveJsonModule": true,
"esModuleInterop": true
},
}
I am several days, without finding why. Thank you.
Here you can see the error.
Now mark it in console, but not in the file.
Just faced a similar problem and found the solution on typescriptlang.org. You need to enable following option:
resolveJsonModule -
Allows importing modules with a ‘.json’ extension, which is a common practice in node projects. This includes generating a type for the import based on the static JSON shape.
TypeScript does not support resolving JSON files by default.
So enabling this option in you tsconfig.json under compilerOptions should do the job:
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": [],
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"strict": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
}
Maybe you also need to enable allowSyntheticDefaultImports to avoid eslint errors.
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!
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.
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.