Format with yapf is silently erroring - visual-studio-code

Using the Python extension, with yapf - nothing happens when I hit format:
VSCode Version: 1.0.0
OS Version: OSX 10.11.4
My workspace settings:
// Place your settings in this file to overwrite the default settings
{
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/js-build": true
},
"editor.scrollBeyondLastLine": false,
"python.pythonPath": "/Users/joshma/.envs/venv/bin/python",
"python.linting.flake8Path": "/Users/joshma/.envs/venv/bin/flake8",
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"editor.formatOnType": true,
"python.formatting.provider": "yapf",
"python.formatting.yapfPath": "/Users/joshma/.envs/venv/bin/yapf"
}
The steps I took:
Rewrite a function call to foo('a' )
Verify that running cat path/to/file.py | yapf formats that line to be foo('a')
Select entire file, cmd + shift + p, Format Code.
Nothing happens :(
It's possible I don't have some path/configuration set up correctly - is there some way to debug this?

I think you are missing this option,
python.formatting.formatOnSave
This is my configuration and the formatting is working,
"python.formatting.formatOnSave": true,
"python.formatting.provider": "yapf",
"python.formatting.yapfPath": "/usr/bin/yapf"

Try only to Format On Save option:
Press Cmd + ,
Search for Format On Save option and chack it on.
Or add the following in settings.json:
{
"python.formatting.provider": "yapf",
"editor.formatOnSave": true,
}

Related

How to fix broken settings.json in VS code?

I was trying out the customizations from this post (
Change highlight text color in Visual Studio Code) but it broke my VS Code settings.json.
I followed the first answer, the highlighting now works.
But when I click on the top to bring up the "Menu Bar", I get the message:
Unable to write into user settings. Please open the user settings to correct errors/warnings in it and try again.
{
"workbench.colorTheme": "One Monokai",
"security.workspace.trust.untrustedFiles": "open",
"files.autoSave": "afterDelay",
"editor.minimap.enabled": false,
"editor.wordWrap": "on",
"window.commandCenter": false,
"workbench.layoutControl.enabled": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.mouseWheelZoom": true,
"html.hover.references": false,
"css.hover.references": false,
"less.hover.references": false,
"scss.hover.references": false,
"window.menuBarVisibility": "compact",
"window.zoomLevel": 1,
"editor.tokenColorCustomizations": {
},
"workbench.colorCustomizations": {
"editor.selectionBackground": "#e788ff7c",
"editor.selectionHighlightBackground": "#ff00005b",
"editor.selectionHighlightBorder": "#fbf300e0", ##border when you select
"editor.findMatchBackground": "#f352fe8f",
"editor.findMatchHighlightBackground": "#8e52fe9e",
"editor.findMatchHighlightBorder": "#fbf300e0" ##border when you search for something
}
}
I'm not sure what should I do to fix this issue.
Comments should start with //, not with ##.
VS Code's settings.json follows JSON with Comments (jsonc) mode:
https://code.visualstudio.com/docs/languages/json#_json-with-comments
In addition to the default JSON mode following the JSON specification, VS Code also has a JSON with Comments (jsonc) mode. This mode is used for the VS Code configuration files such as settings.json, tasks.json, or launch.json. When in the JSON with Comments mode, you can use single line (//) as well as block comments (/* */) as used in JavaScript.
In addition, the editor should have shown you that something was wrong.

In vscode editor after adding the cucumber feature file line appears in different format

In vscode editor, I have typed the feature file line and vs code display the autosuggestion, once I choose from the autosuggestion, below line gets added in editor in following broken format, And I click on the ("|')[^\1]*\1 action link. Could someone please advise the issue here ?
Original feature file line is as follows; And I click on the "Add" action link
Below is my settings.json file;
{
"cucumberautocomplete.steps": [
"tests/cypress/integration/**/*.js",
"cypress/integration/**/*.js"
],
"cucumberautocomplete.customParameters": [
],
"cucumberautocomplete.onTypeFormat": true,
"cucumberautocomplete.formatConfOverride": {
},
"git.ignoreWindowsGit27Warning": true,
"cucumberautocomplete.pages": {},
"git.enableSmartCommit": true,
"git.confirmSync": false,
"git.autofetch": true,
"diffEditor.ignoreTrimWhitespace": false
}
Versions:
cypress-cucumber-preprocessor: "^2.5.5",
VS code : 1.65.2
Operating system: Ubuntu 20.04

VS Code with Prettier/ESLint uses wrong indentation

Prettier in VS Code uses the wrong indentation, even after I changed all the places I can think of to a width of "4".
Here are my file contents (some are maybe not necessary, but I added them while trying to fix it):
c:\Users\jp\Documents\Repositories\Game\Client\.prettierrc.js
module.exports = {
semi: true,
trailingComma: "none",
singleQuote: false,
printWidth: 120,
tabWidth: 4,
endOfLine: "auto",
trailingComma: "none"
};
c:\Users\jp\Documents\Repositories\Game\Client\.editorconfig
indent_size = 4
c:\Users\jp\Documents\Repositories\Game\Client\.eslintrc.js
module.exports = {
parser: "#typescript-eslint/parser", // Specifies the ESLint parser
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: "module", // Allows for the use of imports
ecmaFeatures: {
jsx: true // Allows for the parsing of JSX
}
},
settings: {
react: {
version: "detect" // Tells eslint-plugin-react to automatically detect the version of React to use
}
},
extends: [
"plugin:react/recommended", // Uses the recommended rules from #eslint-plugin-react
"plugin:#typescript-eslint/recommended", // Uses the recommended rules from the #typescript-eslint/eslint-plugin
"plugin:prettier/recommended", // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
"prettier"
],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "#typescript-eslint/explicit-function-return-type": "off",
"no-var": "error", // preference for let and const only
"prefer-const": "error",
"react/react-in-jsx-scope": "off",
"#typescript-eslint/no-empty-function": "off",
"react/prop-types": "off",
"prettier/prettier": [
"warn",
{
semi: true,
trailingComma: "none",
singleQuote: false,
printWidth: 120,
tabWidth: 4,
endOfLine: "auto",
trailingComma: "none"
}
]
}
};
c:\Users\jp\Documents\Repositories\Game\Client\.vscode\settings.json
{
"editor.formatOnSave": true,
"editor.formatOnType": true,
"prettier.tabWidth": 4,
"editor.tabSize": 4,
"jestrunner.jestCommand": "npm run test -- --watchAll=false"
}
My VS Code configuration is set to "4,", and in the bottom bar in VS Code it's set to "4". I also set "detect indendation" to false.
Here is what the Prettier extension output says when I format the document:
["INFO" - 17:18:30] Formatting file:///c%3A/Users/jp/Documents/Repositories/Game/Client/src/App.tsx
["INFO" - 17:18:30] Using config file at 'c:\Users\jp\Documents\Repositories\Game\Client\.prettierrc.js'
["INFO" - 17:18:30] Using ignore file (if present) at c:\Users\jp\Documents\Repositories\Game\Client\.prettierignore
["INFO" - 17:18:30] File Info:
{
"ignored": false,
"inferredParser": "typescript"
}
["INFO" - 17:18:30] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 17:18:30] Prettier Options:
{
"filepath": "c:\\Users\\jp\\Documents\\Repositories\\Game\\Client\\src\\App.tsx",
"parser": "typescript",
"semi": true,
"trailingComma": "none",
"singleQuote": false,
"printWidth": 120,
"tabWidth": 3,
"endOfLine": "auto"
}
["INFO" - 17:18:30] Formatting completed in 0.027ms.
It even says it found the right configuration file, yet uses the wrong indentation.
I restarted VS Code while making the changes to make sure nothing was cached.
In the parent path no .editorconfig is present.
I just don't have any idea where Prettier may take the wrong indentation from...
Edit: When I use the "Quick Fix" with "Fix all prettier/prettier problems", it uses the correct indentation. Formatting on save or Using "Format document" uses the wrong one. Output of the extension output window is the same.
Check if your detect indentation has been enabled. Disable it.
It's not obvious at first, but prettier has order of reading custom configs and is this one according to documentation:
Prettier uses cosmiconfig for configuration file support. This means you can configure Prettier via (in order of precedence):
"prettier" key in your package.json file.
prettierrc file written in JSON or YAML.
.prettierrc.json, .prettierrc.yml, .prettierrc.yaml, or .prettierrc.json5 file.
.prettierrc.js, .prettierrc.cjs, prettier.config.js, or prettier.config.cjs file that exports an object using module.exports.
.prettierrc.toml file.
I can only assume you forgot to check configuration in package.json, and remove these settings from there.

vscode format modified lines with eslint

There are several developers working in my current project with different coding styles. Therefore, I need to configure my vscode with settings:
formatted only lines that were changed by me
formatting should run only when saving
possible to switch from eslint to tslint
My current config:
{
"editor.formatOnPaste": false,
"editor.formatOnType": false,
"editor.formatOnSave": false,
"editor.insertSpaces": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[typescript]": {
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
},
"[javascript]": {
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
},
"[json]": {
"editor.formatOnSave": true
},
}
Well, I would also hope to hear how developers solve a similar problem when working in Vim (because sometimes I use it). Thank you!
The August 2020 update came with an option to "Only format modified"
https://code.visualstudio.com/updates/v1_49#_only-format-modified-text
That should cover 1. and 2. i belive.
If you want to format via eslint --fix, thats something that I'm looking for the answer to as well.
only "eslint --fix" modified lines

Cucumber (Gherkin) Full support extension for VS Code was unable to find step for

I'm using VS Code and Cucumber extension https://marketplace.visualstudio.com/items?itemName=alexkrechik.cucumberautocomplete&ssr=false#overview doesn't work.
This is my settings.json in .vscode folder:
{
"cucumberautocomplete.steps": [
"src/step_definitions/*.js",
],
"cucumberautocomplete.syncfeatures": "src/features/*feature",
"cucumberautocomplete.strictGherkinCompletion": true,
"cucumberautocomplete.strictGherkinValidation": true,
"cucumberautocomplete.smartSnippets": true,
"cucumberautocomplete.stepsInvariants": true,
// "cucumberautocomplete.pages": {
// "users": "test/features/page_objects/users.storage.js",
// "pathes": "test/features/page_objects/pathes.storage.js",
// "main": "test/features/support/page_objects/main.page.js"
// },
"cucumberautocomplete.skipDocStringsFormat": true,
"cucumberautocomplete.formatConfOverride": {
"And": 3,
"But": "relative",
},
"cucumberautocomplete.onTypeFormat": true,
"editor.quickSuggestions": {
"comments": false,
"strings": true,
"other": true
},
"cucumberautocomplete.gherkinDefinitionPart": "(Given|When|Then)\\(",
"cucumberautocomplete.stepRegExSymbol": "'"
}
And this is what I have added to settings.json of VS Code:
{
"workbench.colorTheme": "Default Light+",
"editor.quickSuggestions": true,
"window.zoomLevel": 0
}
When in my feature file I get the message for each line:
"Was unable to find step for "Given I am on the dashboard page"cucumberautocomplete"
Can someone help to resolve this issue and make it work for VS Code?
Kind regards,
mismas
So it finally worked when I:
I. deleted .vscode/settings.json (including the folder)
II. added following in global settings.json of Visual Sudio Code (the one in Users etc directory)
{
"workbench.colorTheme": "Default Light+",
"editor.quickSuggestions": true,
"window.zoomLevel": 0,
"gherkin-autocomplete.featuresPath": "src/features",
"cucumberautocomplete.steps": [
"src/step_definitions/*.js",
],
"cucumberautocomplete.syncfeatures": "src/features/*feature",
}
III. restarted VS Code
Either is something wrong with the plugin => meaning they didn't implemented as they think it should work or documentation is out dated ...
I had to remove the line
"cucumberautocomplete.stepRegExSymbol": "'"
and then it worked for me.
Just remove or comment on below line from setting.json
"cucumberautocomplete.stepRegExSymbol": "'"
It worked for me.
Windows10:
navigate to %APPDATA%\Code\User (which is VScode config folder)
add
"gherkin-autocomplete.featuresPath": "features",
"cucumberautocomplete.steps": [
"features/step_definitions/*.js",],
"cucumberautocomplete.syncfeatures": "features/*feature"
restart vscode