Flutter linter rules and structure in analysis_options.yaml file - flutter

I have been looking off and on for a few days now and I'm trying to customize the rules for linting my flutter project. I'd like to turn off the obvious warnings like unused local variables. Yet when I enter it into the rules section it doesn't work amongst other rules. Yet some do work.
I'm also confused as to the formatting. I see some answers on the internet that use a hyphen then the rule where others are stating the rule with a colon and a true or false. I tried the hyphen and I get a block mapping type of error thrown at me.
Here is my file right now...
include: package:flutter_lints/flutter.yaml
# include: package:lint/analysis_options.yaml
linter:
rules:
always_declare_return_types: false
use_key_in_widget_constructors: false
unused_element: false
unused_local_variable: true
unused_import: false
avoid_print: false
prefer_const_constructors: false
require_trailing_commas: true
always_use_package_imports: false
The trailing commas one worked but the more annoying and obvious warnings I cant seem to suppress.
Can someone please clarify the structure and maybe why the some rules are working and some arent?
If I do the quick fixes inside the files to ignore them it works but I want them project wide.
EDIT
well the unused_local_variable is the warning that started me on this quest for information and understanding of how the analysis_options file works.

Related

How to fix a specific lint warning for the entire project?

There are many lint warnings in different files of my project like:
Prefer const with constant constructors.
Use key in widget constructors.
...
Unnecessary string interpolation.
Is there a way to only fix a particular warning, something like
dart fix prefer_const_constructors
PS: I don't want to fix all the warnings, for that I can run dart fix --apply.
Yes, It is possible by changing lint rules. For time being, you have to add only rules which you want to fix and ignore all others.
Follow these steps
In the project, you have to create analysis_options.ymal file. The content of the file will look like this.
linter:
rules:
prefer_const_constructors: true
More details here
After that try to run dart fix, since only one lint rule is enabled it only gives you suggestions for that only.
To ignore a single line, you can add a comment above the line:
// ignore: non_constant_identifier_names
final NEW = 'NEW';
To ignore for the whole file, you can add a comment at the top of the file:
// ignore_for_file: non_constant_identifier_names
To ignore for the whole project, you can set the rule to false in your analysis_options.yaml file:
include: package:lints/recommended.yaml
linter:
rules:
non_constant_identifier_names: false
Refer this for more
Customizing static analysis
Setting up Lint Rules in Dart-Flutter

Eclipse XML Validation - how to exclude certain files?

Since the reactions in the Eclipse WTP forum were not really helpful I try to maybe get an answer here:
In our test folders we have a couple of (purposely) faulty XML files.
EACH and EVERY time I do a full rebuild these are flagged as validation errors!
No matter what I specify in Preferences -> Validation -> XML Validation -> Settings under "Exclude Group: these files keep getting validated and hence flagged as build errors and this is mighty annoying!
What syntax is expected for a "Folder or Filename" rule?
Our faulty testfiles are named like "Filename-01.xml" to "Filename-30.xml" but strings like "Filename*.xml" or "Filename*" (with or without the case sensitive flag checked) obviously don't match. Whether specifying the full pathname or just the directory-local name or even trying with RegEx syntax (i.e. "Filename.*") didn't make any difference.
What is the secret sauce to get this "Exclude Group" working?
Or is this simply a bug that we have to live with (because I have little hope that this will ever get fixed...)?

VSCode codeActionsOnSave ignore specific file

I'm using organizeImports on save, but there are some instances where the order matters and this causes an issue. I can't find anywhere if there's a way to simply ignore a page, either through comments within the page (ideally) or within the config settings.
Perhaps there's an extension that provides this functionality if not baked in. In any case, really appreciate any help tracking down a solution for this.
Couldn't find how to do it properly but here is a solution that might solve your end needs if you use prettier.
The way I handled organizeImports selectively for files was as follow.
1 - Make sure your default formatter is prettier (as explained below)
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
2 - In your settings set formatOnSave to true but organizeImports to false such as below.
{
"editor.codeActionsOnSave": {
"source.organizeImports": false
},
"editor.formatOnSave": true
}
3 - Install https://github.com/simonhaenisch/prettier-plugin-organize-imports
This is a prettier plugin that allows organizing import as part of the prettier formatting and has an option to disable organize import for files (i.e. // organize-imports-ignore )
If you're using ESLint (which I would highly recommend), you can use sort-imports or import/order (via eslint-plugin-import) to sort your import statements across the entire project, then ignore the rule in specific files/regions with special comments, like this:
/* eslint-disable import/order */
import * from "abcdefg";
import "cool-module";
// etc...
VSCode has a great ESLint plugin, which in combination with
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
},
will auto format and fix your code whenever the file is saved.

Ignore or bypass errors phpcs

How to bypass or ignore specific errors/warnings in vscode?, I am using phpcs.
What you are looking for is to ignore the warning and/or errors, that are notified by the phpcs in the console of the vscode.
For Warnings
Use the following config in your settings.json
"phpcs.showWarnings": false,
this will remove all the warnings displayed in the output console.
For Errors
You should go trough the DOCS for complete details but to remove the errors related to the Doc block and the formatting standards you can set the
"phpcs.errorSeverity": 6,
Although it is mostly used for testing or code reviews to check for total warnings and errors by setting different values for both, but for development i dont do that and keep it to the default value that is 5 but you can get rid of those errors above in your image.
The vscode-phpcs refers to the GitHub project squizlabs/PHP_CodeSniffer, which integrates PHP_CodeSniffer into VSCode.
Its readme mentions the setting phpcs.ignorePatterns:
An array of glob patterns to skip files and folders that match when linting your documents.
{
"phpcs.ignorePatterns": [
"*/ignored-file.php",
"*/ignored-dir/*"
]
}
That refers to PHP CodeSniffer --ignore option.
That is not what you want exactly, since it ignores all errors on a given set of file.
But you could use PHP CodeSniffer syntax to ignore errors:
Ignoring Parts of a File
Some parts of your code may be unable to conform to your coding standard. For example, you might have to break your standard to integrate with an external library or web service.
To stop PHP_CodeSniffer generating errors for this code, you can wrap it in special comments. PHP_CodeSniffer will then hide all errors and warnings that are generated for these lines of code.
$xmlPackage = new XMLPackage;
// phpcs:disable
$xmlPackage['error_code'] = get_default_error_code_value();
$xmlPackage->send();
// phpcs:enable
Again, not exactly what you want, since you have to specify that on a file-by-file basis
You can disable multiple error message codes, sniff, categories, or standards by using a comma separated list.
You can also selectively re-enable just the ones you want.
The following example disables the entire PEAR coding standard, and all the Squiz array sniffs, before selectively re-enabling a specific sniff. It then re-enables all checking rules at the end.
// phpcs:disable PEAR,Squiz.Arrays
$foo = [1,2,3];
bar($foo,true);
// phpcs:enable PEAR.Functions.FunctionCallSignature
bar($foo,false);
// phpcs:enable

javascript turn off code formatting

vscode is great, but it oversteps boundaries. I'd like to maintain my coding style but seem to be constantly forced into some invisible 'standard', defined by MSoft, I suppose. At any rate, I have "javascript.format.enable": false set and yet it still insists on changing my code.
Take something simple, like dothis(y+2), gets converted to dothis(y + 2) on Save (Ctrl-S). There are many times when I just want what I typed in. How can I get vscode to help me out instead of imposing its own 'standard'?
Do you have "editor.formatOnSave": true in user settings or folder settings? Or, an extension installed that may be doing this?