Flutter - Objectbox generation additional options for non CamelCase - flutter

When I run the generator in flutter, it will generate my objectbox.g.dart file as expected and works fine but I get 100's of lint warnings
Name non-constant identifiers using lowerCamelCase.
I don't have my properties set with camel case, So I have properties like CustomerID, Billing_Address1 etc.
In my model files I have
// ignore_for_file: non_constant_identifier_names
which stops the linting warnings. I prefer this style for models.
I want the generated file to also have this added when rebuilt. It already adds
// ignore_for_file: camel_case_types
So my question is how can I default this also?
Thanks

Just add analysis_options.yaml to your project, e.g. with the following contents:
linter:
rules:
non_constant_identifier_names: false
or
analyzer:
exclude:
- lib/objectbox.g.dart

Related

How to change .vscode/ path from $HOME?

Even typing
code --user-data-dir "$XDG_DATA_HOME/vscode" --extensions-dir "$XDG_DATA_HOME/vscode/extensions"
A directory appears in $HOME with the following structure:
.vscode
└── argv.json
The file contains
// This configuration file allows you to pass permanent command line arguments to VS Code.
// Only a subset of arguments is currently supported to reduce the likelihood of breaking
// the installation.
//
// PLEASE DO NOT CHANGE WITHOUT UNDERSTANDING THE IMPACT
//
// NOTE: Changing this file requires a restart of VS Code.
{
// Use software rendering instead of hardware accelerated rendering.
// This can help in cases where you see rendering issues in VS Code.
// "disable-hardware-acceleration": true,
// Enabled by default by VS Code to resolve color issues in the renderer
// See https://github.com/microsoft/vscode/issues/51791 for details
"disable-color-correct-rendering": true,
// Allows to disable crash reporting.
// Should restart the app if the value is changed.
"enable-crash-reporter": true,
// Unique id used for correlating crash reports sent from this instance.
// Do not edit this value.
"crash-reporter-id": "687dbf38-06cb-438c-ae8f-d9a2e2e847f7"
}
How to get rid of .vscode in my $HOME path?

Flutter linter rules and structure in analysis_options.yaml file

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.

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

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.

generated file related to entity mapping - what is it, and is it reliably re-auto-generated?

I had a file auto-generated, called Core.Views.cs, inside a folder where we have a Core.edmx file. This looks like something related to the entity framework, although I've not come across this specific type of auto-generated file before. The file starts like this:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.296
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[assembly: System.Data.Mapping.EntityViewGenerationAttribute(typeof(Edm_EntityMappingGeneratedViews.ViewsForBaseEntitySetsA6A322F63F6E541F50AC0C3927F34D34A0332BA66EF2300CE900CF04516540EA))]
namespace Edm_EntityMappingGeneratedViews
{
If I check it into source control, it breaks our TFS build as the build process seems to be trying to re-generate the file so it creates a conflict
What does this file do, and is it always reliably regenerated from source code?