How to add new line after and before method declarations in classes using prettier? - tslint

What settings need to be configured to add a new line before and after method declaration in classes in typescript files using prettier plugin in vs code editor?
How can we achieve by writing any rule in .prettierrc or tslint.json file?
current behavior is
function one(){
// some code
}
function two(){
// some code
}
expected result
function one(){
// some code
}
function two(){
// some code
}
I have tried with below line in tslint.json
"lines-between-class-methods": "true"
but did not works

What #lakshan mentions is an ESLint rule. There is a TSLint rule that accomplishes what you are looking for but on in regards to class methods.
https://github.com/chinchiheather/tslint-lines-between-class-members
Run
npm install --save-dev tslint-lines-between-class-members
Add
tslint.json
{
"rulesDirectory": [
"node_modules/tslint-lines-between-class-members"
],
"rules": {
"lines-between-class-members": true,
}
}

lines-between-class-members is a built-in of ESLint, the replacement of TSLint which is now deprecated. This rule works for both TypeScript and JavaScript and --fix is supported. See https://eslint.org/docs/rules/lines-between-class-members for full details. You probably want to set exceptAfterSingleLine to true for TypeScript.
To make ESLint work for TypeScript you have to install npm packages #typescript-eslint/parser and #typescript-eslint/eslint-plugin and include both parser and plugin in your ESLint config. See typescript-eslint docs.
{
"parser": "#typescript-eslint/parser",
"plugins": ["#typescript-eslint"],
"rules": {
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }]
}
}

try this, inside your es-lint rules,
"lines-between-class-members" : ["error", "always"]
It will throw you an error if you violate the condition. & I think you must declare your functions inside a class in order that to work.
to add to that, you might not get auto-fix with prettier, because It turns out empty lines are very hard to automatically generate. The approach that Prettier takes is to preserve empty lines the way they were in the original source code.

Related

How to include some deps and source codes in Gradle conditionally

In a Maven project, it is easy to add extra deps and include extra source codes via defining a new Maven profile.
How to do the following things in a Gradle project.
Includes extra deps
Includes another source codes directory
And for example, use an extra property existence(eg. add to command line) to decide to activate it or not. I am not sure the best way in Gradle world.
I am not recommending your approach.
But it can be done via - project properties from gradle command line and groovy if (condition) { } for dependencies and multiple sourceset defs
on command line
gradle build -PbProfile=extra1
ext.buildFlag = 'default'
if (project.hasProperty('bProfile')) {
ext.buildFlag = property('bProfile')
}
println "running profile - ${buildFlag}"
dependencies {
//common-deps
if ("extra1".equals(buildFlag)) {
//extra deps
}
}
if ("extra1".equals(buildFlag)) {
//custom sourceset def
} // more else if needed
I use conditionally applied sub-configurations. This is done thru the apply from directive:
if (project.hasProperty('browsers')) {
ext.browsers.split(',').each {
def browser = it.trim()
if (browser) {
apply from: "${browser}Deps.gradle"
}
}
}
This block checks for specification of the browsers property (either from gradle.properties or the -P command line argument). If this property is defined, I split the property's value on commas and apply sub-configurations whose names conform to the pattern <browser>Deps.gradle.
The project in which I use this pattern is here

How to include a .properties file in i18n.properties file on SAPUI5?

Environement
Framework: SAPUI5 V1.38.39
Issue
Well, the issue may semble stupid but is it as follow :
I have an application with a lot of text, which makes very huge i18n files, that why I wanted to separate them into several files for the files to be cleaner. For example :
an i18n.properties including i18n_food.properties, i18n_ingredient.properties, etc.
an i18n_en.properties including i18n_food_en.properties, i18n_ingredient_en.properties, etc.
an i18n_de.properties including i18n_food_de.properties, i18n_ingredient_de.properties, etc.
an i18n_fr.properties including i18n_food_fr.properties, i18n_ingredient_fr.properties, etc.
Attemps
What I try is to make as for Apache .properties files meaning :
#i18n.properties
include = i18n_food.properties
#i18n_food.properties
recipeSelection = A selection of recipe
recipeDetail = Recipe details
But it doesn't work, in the view, I bind with "{i18n>recipeDetail}" and instead of showing "Recipe details" it shows "recipeDetail"
Check you manifest file, whether you have updated your new i18n file name
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "xxxx.xxxx.i18n.i18n",
"bundleName": "xxxx.xxxx.i18n.i18n_food"
}
}
}

How to nest interfaces using File Nesting in ASP.Net Core

I want to use Microsoft's custom file nesting option in Visual Studio to nest implementation class files with their "parent" interfaces, so in this example, I would like ReportRepository.cs to appear nested under IReportRepository.cs in the solution explorer. The same should be for all repositories.
I have created the .filenesting.json file in the root of the solution, but I have no idea how to use it and documentation is very sparse.
Does anyone know how I can achieve this in Visual Studio 2019?
As far as I can gather it is not possible to group by prefixes. You can only group by extensions or suffixes, or entire file names.
This means you can't define a rule for this. However there are 2 options:
Define a rule for each file
Change your naming scheme
Defining a rule for each file
To define a rule for each file you would use the fileToFile provider.
This would look like so:
{
"help": "https://go.microsoft.com/fwlink/?linkid=866610",
"root": true,
"dependentFileProviders": {
"add": {
"fileToFile": {
"add": {
"IInvestigationRepository.cs": [ // Parent file
"InvestigationRepository.cs" // Nested file
],
"IReporterRepository.cs": [ // Parent file
"ReporterRepository.cs" // Nested file
]
...
}
}
}
}
}
Using a different naming scheme
Alternatively, if the first option is not to your liking, you could use a different naming scheme for your files, and let the classes keep their old names.
Then you could use the fileSuffixToExtension provider like such:
{
"help": "https://go.microsoft.com/fwlink/?linkid=866610",
"root": true,
"dependentFileProviders": {
"add": {
"pathSegment": {
"add": {
".DefaultImplementation.cs": [
".cs"
]
}
}
}
}
}
This would map
IInvestigationRepository.DefaultImplementation.csto IInvestigationRepository.cs,
IReporterRepository.DefaultImplementation.csto IReporterRepository.cs
and so on.
This would also make the purpose of your files clearer, as just having the same name doesn't tell you what it's doing with the Interface, just that is has something to do with it.
If you don't want to use a notation with . and would prefer to use -, you can do that by replacing "pathSegment" with "fileSuffixToExtension", and replacing ".DefaultImplementation.cs" with "-DefaultImplementation.cs"
We use the following pattern in our .csproj files to auto nest concretes with their interfaces (if they reside in the same directory).
<ItemGroup>
<Compile Update="**\*.cs">
<DependentUpon>$([System.String]::Copy(I%(Filename).cs))</DependentUpon>
</Compile>
</ItemGroup>
I know that the question was to use the custom nesting options in Visual Studio; however, until Microsoft adds prefix functionality, this method does the trick.

Gradle Build Failure: Couldn't find outer class

When trying to build, I get this stacktrace:
Exception in thread "main" java.lang.NullPointerException: Couldn't find outer class com/xxx/CheckListPresenter$onAttached$1$5 of com/xxx/CheckListPresenter$onAttached$1$5$1
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:1079)
at com.google.devtools.build.android.desugar.ClassVsInterface.isOuterInterface(ClassVsInterface.java:56)
at com.google.devtools.build.android.desugar.InterfaceDesugaring.visitOuterClass(InterfaceDesugaring.java:246)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:638)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:477)
at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:361)
at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:314)
at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:711)
I checked the CheckListPresenter class and there doesn't appear to have any issues. I tried deleting the class just to see if it would build, but the error just moved on to another class stating the same issue.
The last time I touched this code was a good few months ago, so I am not sure what triggered the change.
Things that may matter: This is an Android project. This is written in Kotlin. This fails on the transformClassesWithDesugarForDebug gradle task
Edits
These are all just stabs in the dark I tried:
Creating a new project and moving in only my source code and gradle files.
Dropping from java 8 to 7.
Different version of JDK. I have tried 1.8.0_151 and 1.8.0_152.
Adding javaMaxHeapSize "4g" to build.gradle.
Upgrading everything: gradle wrapper and every dependency.
Removed Dagger in favor of Koin
Removed Kapt
Used both Preview and Stable releases of Android Studio
Here is my build scan for what good it will do
New discovery:
This is the snippet of code that is killing me:
view?.let { v ->
v.getCancelClicks()
.doOnSubscribe({ disposables.add(it) })
.subscribe({
v.showExitDialog()
.filter { it }
.subscribe({
cancel()
}, this::onError)
}, this::onError)
}
What is strange, is neither one of these alone will give me issues
view?.let { v ->
v.getCancelClicks()
.doOnSubscribe({ disposables.add(it) })
.subscribe({
//removed
}, this::onError)
}
}
or
view?.let { v ->
v.showExitDialog()
.filter { it }
.subscribe({
cancel()
}, this::onError)
}
But together they are a problem.
Something else of note, view is defined in the base class and is a generic.
Currently, my work around is to remove view?.let{ and just use view!!. This is obviously a bug, but I am not sure who to report it to. Gradle, Kotlin, JetBrains, God?
The problem resolved itself when I added android.enableD8.desugaring = true to gradle.properties
I have a way to work around this error: java.lang.NullPointerException: Couldn't find outer class com/iconfitness/iconaudit/common/fragments/SettingsFragment$onCreate$1$1 of com/iconfitness/iconaudit/common/fragments/SettingsFragment$onCreate$1$1$1.
Just move this block code
v.showExitDialog()
.filter { it }
.subscribe({
cancel()
oo other method. I don't meet this problem anymore. I hope this will help you.
The issue is filed here https://issuetracker.google.com/issues/72750890.
Both solutions mentioned there worked for me:
adding classpath 'com.android.tools.build:gradle:3.0.1' to build.gradle or adding android.enableD8.desugaring=true to gradle.properties
As a workaround you can substitute let by null checking. At least code started to compile after this
if (view!=null)
view.showExitDialog()
.filter { it }
.subscribe({
cancel()
}, this::onError)
}

How do I compile against local file in gradle?

For each sub-project in our build, we have a structure like this:
apply from: '../dependencies.gradle'
dependencies {
... omitting other dependencies ...
compile libraries.poi
}
These libraries are defined in dependencies.gradle, which looks like this:
ext.libraries = [
... omitting other libraries ...
poi: [
'poi:poi:3.9.custom.1',
'poi:poi-ooxml:3.9.custom.1',
'poi:poi-ooxml-schemas:3.9.custom.0',
'poi:poi-scratchpad:3.9.custom.0',
],
... omitting other libraries ...
]
A few days ago I wanted to try something against a nightly build of POI. Nightly builds don't go into their repository, so I'm forced to try and get it to work with local files.
Looking in the docs, you're supposed to use files(...) for this, so I tried this:
poi: [
files('/path/to/poi-3.14-beta1/poi-3.14-beta1-20151027.jar'),
files('/path/to/poi-3.14-beta1/poi-3.14-ooxml-20151027.jar'),
files('/path/to/poi-3.14-beta1/poi-3.14-ooxml-schemas-20151027.jar'),
files('/path/to/poi-3.14-beta1/poi-3.14-scratchpad-20151027.jar'),
],
When I run this, I get an error:
* What went wrong:
A problem occurred evaluating root project 'product'.
> Cannot convert the provided notation to an object of type ModuleVersionSelector: file collection.
The following types/formats are supported:
- Instances of ModuleVersionSelector.
- String or CharSequence values, for example 'org.gradle:gradle-core:1.0'.
- Maps, for example [group: 'org.gradle', name:'gradle-core', version: '1.0'].
- Collections or arrays of any other supported format. Nested collections/arrays will be flattened.
So really it seems like files() does not actually work, as it doesn't return one of the things listed here.
What is the correct way to do it? (Assuming it's even possible!)
Edit: More information
Now that I updated to Gradle 2.8, I get a line number pointing at the problem. It points at some custom build code which we put in to work around Gradle sucking at dependency resolution:
resolutionStrategy {
libraries.each {
libraryName, libraryList ->
libraryList.each {
library -> force library // 👈 this line
}
}
failOnVersionConflict()
}
So I take it the problem is that force doesn't support all the same things that other methods support?
My crap workaround for a workaround is to filter out elements of type FileCollection:
resolutionStrategy {
libraries.each { libraryName, libraryList ->
[libraryList].flatten()
.findAll { library ->
!(library instanceof FileCollection)
}
.each { library -> force library }
}
failOnVersionConflict()
}
Maybe there is a better way.

Resources