Cascading eslint config file - visual-studio-code

I have few questions about cascading eslint config file:
Can I use eslint like a tsconfig.json (in typescript) where I have a root .eslintrc.yml and I can extend/cascade that to each .eslintrc.yml for each folder (project)? I'm not sure if this is what the documentation says here.
If I can extend a root config file how does it work on the case of extends option where sometimes the order is important like on the case of eslint-config-prettier as mentioned on their docs. There it says:
Make sure to put it last, so it gets the chance to override other configs.
Correct me if my understanding is correct that with plugins option the order is not important but on extends sometimes the order is important like what I mentioned on question #2.
If the order is important on extends option, how can I make sure that it follows the order when I have an extension like eslint-plugin-prettier where it should be the last when I'm not using cascading. For example:
If I'm not using cascading it should be like this as what is mentioned here:
extends:
- "some-other-config-you-use"
- "prettier"
- "prettier/#typescript-eslint"
- "prettier/react"
If I'm using cascading my setup will be like this:
# root
root: true
parser: "#typescript-eslint/parser"
extends:
- "eslint:recommended"
- "plugin:#typescript-eslint/recommended"
- "prettier"
- "prettier/#typescript-eslint"
# sub-folder
env:
browser: true
extends:
- "plugins:react/recommended"
- "plugins:jsx-a11y/recommended"
- "prettier/react"

root: true
parser: "#typescript-eslint/parser"
extends:
- "eslint:recommended"
- "plugin:#typescript-eslint/recommended"
- “./path/your_other_config”
- "prettier"
- "prettier/#typescript-eslint"

Related to this, I was running into an error after creating the .eslintrc.js file in a subdirectory:
Parsing error: "parserOptions.project" has been set for #typescript-eslint/parser.
The file does not match your project config
The solution was to specify ignorePatterns: ['.eslintrc.js'], in the root config, as discussed here.

Related

Is there a build_extensions rule in build.yaml to output all generated Flutter models in a common directory?

I am trying to create a build_extensions rule in build.yaml for builders freezed and json_serializable to output all generated models in the directory lib/generated/model, irrespective of their original location that matches lib/**/*.dart.
What I have tried:
I would expect '^lib/**/{{}}.dart': 'lib/generated/model/{{}}.g.dart' to work, but it doesn't match any Dart files.
I also tried things like '^lib/{{path}}/{{file}}.dart': 'lib/generated/model/{{file}}.g.dart' but {{path}} needs to be matched again in the destination, as per documentation (why even enforce this?).
Example:
Base model location: lib/core/feature/profile/profile.dart
Generated outputs after calling flutter pub run build_runner build --delete-conflicting-outputs:
lib/generated/model/profile.g.dart
lib/generated/model/profile.freezed.dart
My current build.yaml (which generates .g.dart and .freezed.dart files in the child generated directory relative to the original model location) is as follows:
targets:
$default:
builders:
source_gen|combining_builder:
generate_for:
- lib/**.dart
options:
build_extensions:
# I want this line to "work":
# '^lib/**/{{}}.dart': 'lib/generated/model/{{}}.g.dart'
'lib/{{path}}/{{file}}.dart': 'lib/{{path}}/generated/{{file}}.g.dart'
freezed:
options:
build_extensions:
# I want this line to "work":
# '^lib/**/{{}}.dart': 'lib/generated/model/{{}}.freezed.dart'
'lib/{{path}}/{{file}}.dart': 'lib/{{path}}/generated/{{file}}.freezed.dart'
field_rename: snake
explicit_to_json: true
json_serializable:
options:
field_rename: snake
explicit_to_json: true
For anyone else looking for a similar solution, turns out it's not possible to place multiple generated outputs into the same directory.
Build extensions need to be written in a way that prevents two different files from emitting the same output file (e.g. if you had lib/a/foo.dart and lib/b/foo.dart, there can't be a single foo.g.dart in lib/generated/model). ** is not something build extensions supports, and {{}} should be used to match multiple chars and then used again in the destination directory. Apart from that, build extensions just match suffixes.
To avoid the problem of different source directories potentially conflicting in the output directory, you'd have to use something like lib/generated/model/{{path}}/{{file}}.g.dart, there's no way to put everything in a single directory, even if you make sure that no generated files will be outputted with the same name in the first place.

When I type "npm run generate" in my code block vscode out and deleting the letter i

When I type "npm run generate" in my code block, codegen generates my graphql file automatically. But while generating vscode is freaking out and deleting the letter i. When I make a new change, I have to constantly change it. Has anyone encountered such a problem before?
My codegen.yml file looks like this:
overwrite: true
schema: "http://localhost:3000/graphql"
#schema:
# - https://***/graphql:
# headers:
# Cookie: "***"
documents: "src/**/*.graphql"
generates:
src/generated/graphql.tsx:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
- "fragment-matcher"
./graphql.schema.json:
plugins:
- "introspection"
It's probably something on your env, replacing io with O.
Could you create a minimal isolated reproduction of this issue, maybe via StackBlitz or CodeSandbox?

Where actually is the syntax error in my github actions yml file

I am actually implementing CI/CD for my application. I want to start the application automatically using pm2. So I am getting the syntax error on line 22.
This is my yml file
This is the error I am getting on github
The problem in the syntax here is related to how you used the - symbol.
With Github actions, you need at least a run or uses field inform for each step inside your job, at the same level of the name field (which is not mandarory), otherwise the github interpreter will return an error.
Here, from line 22, you used something like this:
- name: ...
- run: ...
- run: ...
- run: ...
So there are two problems:
First, the name and the run field aren't at the same yaml level.
Second, your step with the name field doesn't have a run or uses field associated with it (you need at least one of them).
The correct syntax should be:
- name: ...
run: ...
- run: ...
- run: ...
Reference about workflow syntax

How to set a variable from another yaml file in azure-pipeline.yml

I have an environment.yml shown as follow, I would like to read out the content of the name variable (core-force) and set it as a value of the global variable in my azure-pipeline.yamal file how can I do it?
name: core-force
channels:
- conda-forge
dependencies:
- click
- Sphinx
- sphinx_rtd_theme
- numpy
- pylint
- azure-cosmos
- python=3
- flask
- pytest
- shapely
in my azure-pipeline.yml file I would like to have something like
variables:
tag: get the value of the name from the environment.yml aka 'core-force'
Please check this example:
File: vars.yml
variables:
favoriteVeggie: 'brussels sprouts'
File: azure-pipelines.yml
variables:
- template: vars.yml # Template reference
steps:
- script: echo My favorite vegetable is ${{ variables.favoriteVeggie }}.
Please note, that variables are simple string and if you want to use list you may need do some workaraund in powershell in place where you want to use value from that list.
If you don't want to use template functionality as it is shown above you need to do these:
create a separate job/stage
define step there to read environment.yml file and set variables using REST API or Azure CLI
create another job/stage and move you current build defitnion into there
I found this topic on developer community where you can read:
Yaml variables have always been string: string mappings. The doc appears to be currently correct, though we may have had a bug when last you visited.
We are preparing to release a feature in the near future to allow you to pass more complex structures. Stay tuned!
But I don't have more info bout this.
Global variables should be stored in a separate template file. This file ideally would be in a separate repo where other repos can refer to this.
Here is another answer for this

Multiple include(s) in analysis_options.yaml?

I'd like to combine two (or more) analysis_options.yaml files for my project but wasn't able to find a way how to do that.
This works:
include: package:pedantic/analysis_options.yaml
...
This works too:
include: package:flutter/analysis_options_user.yaml # note different "base" lint rules
...
But I'd need something like this:
include:
- package:pedantic/analysis_options.yaml
- package:flutter/analysis_options_user.yaml
...
...which results in following error:
warning: The include file - package:pedantic/analysis_options.yaml
- package:flutter/analysis_options_user.yaml
in /home/.../analysis_options.yaml cannot be found. (include_file_not_found at [...] analysis_options.yaml:1)
Has anyone encountered/resolved same problem?
You can only include one analysis options file.
Plus package:pedantic/analysis_options.yaml and package:flutter/analysis_options_user.yaml
enforce different rules.
Example:
Pedantic does not use empty_statements
analysis_options_user.yaml uses it