How to ignore all lint rules for a file or a project? - flutter

I'm seeing too many lint warnings in my file, for example:
Avoid print calls in production code
Prefer const with constant constructors
Use key in widget constructors
I know how to disable a rule for a specific line or for the entire file, but I want to know is there any way I can disable all these lint warnings with something like
// ignore_for_file: all

According to the documentation,
// ignore_for_file: type=lint
should work. I don't have a project to test it right now though.

in your analysis_options.yaml file:
linter:
rules:
avoid_print: false
# add more here ...
# Available lints see: [https://dart-lang.github.io/linter/lints/index.html][1]

Unfortunately, there is no such comment like that. These lint rules are coming from flutter_lints package which is included in your analysis_options.yaml file, So, open the file and comment this line out:
// include: package:flutter_lints/flutter.yaml
After this, save the file using command + s

Just remove flutter_lints package from pubspec.yaml file.

Related

how to ignore folders in melos packages

working in a monorepo with this structure
monorepo/
examples/
# ...
foo/
packages/
# ...
foo/
# ...
example/ -> examples/foo/
where the example in packages/foo
is a deep link to examples/foo/
that contains a demo app called foo_example
I'm encountering a problem during melos bootstrap
Run melos bootstrap
melos.yaml: Multiple packages with the name `foo_example` found in the workspace, which is unsupported.
To fix this problem, consider renaming your packages to have a unique name.
The packages that caused the problem are:
- foo_example at packages/foo/example
- foo_example at examples/foo
Error: Process completed with exit code 1.
I would like to keep the folders for examples and packages separated
while providing an example readily available for https://pub.dev/
is there a way to exclude the packages/**/example/ folders from melos?
this is how I'm pointing at the packages right now
name: <my_mono_repo>
packages:
- examples/**
- packages/**
scripts:
# ...
always read the docs :)
https://melos.invertase.dev/configuration/overview#ignore
this does the job
ignore:
# e.g. ignore example apps
- "packages/**/example"

Source "#openzeppelin/contracts/token/ERC721/ERC721.sol" not found: File import callback not supported

I've imported the Open Zeppelin ERC721 token standard into my VS Code with the Solidity extension, but see the following warnings on all my OZ import statements:
Screenshot of error
Why is this happening and what is the workaround for this warning?
What I've tried:
change default workspace compiler to localNodeModule (began to throw other warnings like on the pragma solidity line)
Example of solution I've tried
Just install the Solidity+Hardhat Extension ,this will take care of the errror.
run below command
npm install #openzeppelin/contracts
Change the import line like this
import "./node_modules/#openzeppelin/contracts/token/ERC721/ERC721.sol";
You could try this solution here, the only one that helped me.
https://stackoverflow.com/a/72241149/7537543
When you compile programmatically using solc, new syntax was introduced, which you have to include in compile.js.
// New syntax (supported from 0.5.12, mandatory from 0.6.0)
var output = JSON.parse(
solc.compile(JSON.stringify(input), { import: findImports })
);
You should have a helper function for finding imports
function findImports(relativePath) {
//my imported sources are stored under the node_modules folder!
const absolutePath = path.resolve(__dirname, 'node_modules', relativePath);
const source = fs.readFileSync(absolutePath, 'utf8');
return { contents: source };
}
Unfortunately I ran into this error too & just gave the path manually:
import "/home/ev1lclow3n/node_modules/#openzeppelin/contracts/token/ERC721/ERC721.sol";
This solved my error.
(I'm a linux user so path may differ for you)
Thanks ;-)
you have to manually guide the open zepplin import to its source file if you have it downloaded in your node modules then all you have to do is to change its path like this " ../node_modules/" and also make sure to use the latest extension of juan blanco's solidity extension and solidity and hardhat extension and if you are following a tutorial your first lines of codes would probably be import "hardhat/console.sol"; all you have to do here is to manually direct only this file to its designated place and the others would do it by themselves.
What you have to do is:
If you have "Solidity by Juan Blanco" for Truffle and "Solidity by Nomic Foundation" for Hardhdat, and if you are using Hardhat, disable the one by Juan Blanco and just use the one by Nomic Foundation, it just worked for me.
Screenshot
Make sure to create a Hardhat project (npx hardhat) and install:
npm install --save-dev "hardhat#^2.12.7" "#nomicfoundation/hardhat-toolbox#^2.0.0"
npm i #openzeppelin/contracts
Ok. That was a dumb question. Two things you have to do:
(1) Install the OZ library via
npm install #openzeppelin/contracts
(2) If you see Error HH606 (i.e. project can't compile), it's likely because The Solidity version pragma statement in these files doesn't match any of the configured compilers in your config.. Ensure that your pragma version matches the version in your hardhat config.
Hope this helps.

How to disable the warning "Omit type annotations for local variables"? in Dart (with Pedantic Package)

I use the pedantic package in Flutter and I have the following anaylsis_options.yaml file:
include: package:pedantic/analysis_options.yaml # advanced linter
analyzer:
enable-experiment:
- extension-methods
linter:
rules:
omit_local_variables_types: false
# always_specify_types: true
I try to disable the "Omit type annotations for local variables" warning. I can only disable it, I uncomment the last line (see question Dart 2.8.0 sdk: how to globally ignore omit_local_variable_types warning?). But I don't want to specify every type. So that's not what I want.
So how get I disable this warning globally?
I'm not sure if this is a feature that came later than when the question is posted, but according to here you can ignore rules.
So if you want to disable warnings for omit_local_variable_types rule you can do the following in your anaylsis_options.yaml file:
analyzer:
errors:
omit_local_variable_types: ignore

Angular Dart Tutorial - Unable to find modules for some sources

I'm trying to follow the Angular Dart tutorial (https://webdev.dartlang.org/angular/tutorial/toh-pt1) but got stuck after adding some html that makes use of the ngModel directive.
According to the tutorial in order to make use of the ngModel directive one has to add "angular_forms: ^2.0.0" to the pubspec.yaml, import 'package:angular_forms/angular_forms.dart' and add "formDirectives" to the component directives. I did all of that including running "pub get" to get the dependencies but when I run "webdev serve" I get the following error:
[SEVERE] build_web_compilers|entrypoint on test/app_test.dart (cached):
Unable to find modules for some sources, this is usually the result of either a
bad import, a missing dependency in a package (or possibly a dev_dependency
needs to move to a real dependency), or a build failure (if importing a
generated file).
What am I missing?
I had the same the problem. I don't think it mentions explicityly in the tute but after adding angular_forms dependency to the pubspec.yaml file, you need to pull in this new dependency with:
pub get
Hope it helps!

Target URI doesn't exist, when trying to import a package in flutter

I have stumbled upon a problem in importing the package in Flutter, I tried to solve this by running flutter packages get and also shutting down the project in Android studio and reopening it.
import 'package:task_02_category_widget/category.dart';
Here is the line above, and the error I'm running into when I run it gives the following error in the console.
Your application could not be compiled, because its dependencies could
not be established.
The following Dart file:
/Users/username/Documents/flutter_rectangle_2/lib/main.dart
...refers, in an import, to the following library:
package:task_02_category_widget/category.dart
That library is in a package that is not known. Maybe you forgot to
mention it in your pubspec.yaml file?
If task_02_category_widget/category.dart is part of an old project you are reusing you should put it in a folder in your flutter application and include it like "../ folder /task_02_category_widget/category.dart ". If it is part of github repository you have copy pasted from, just copy the file and use the step above. Most probably you are looking for that . In any other case check here to find the source code.
You should have in your project at a file called pubspec.yaml a definition like this:
name: my_app
dependencies:
task_02_category_widget:
Let’s say that your package is laid out as follows:
task_02_category_widget/
lib/
category.dart
Then, you can import it:
import 'package:task_02_category_widget/category.dart';
More information:
https://www.dartlang.org/tools/pub/get-started
https://www.dartlang.org/guides/libraries/create-library-packages