Comments (9)
Would this logic work?
For every line, count the number of leading spaces, spaces
. Replace them with spaces/tabsize
tabs.
from obsidian-linter.
I think so.
One consideration could be to also deal with cases where you have one more space than your tabsize, which would result in tab+space
. But that would rather be another rule, I guess?
from obsidian-linter.
You can pass it in as an option, the user can set
tabsize=2
in the settings. See the other rules for examples.
That would work, but it isn't ideal. Users might not consider that the tabsize set in the Linter plugin is independent from the tabsize set in the Obsidian main setting, leading to unnecessary confusion about the use of that rule
from obsidian-linter.
I was thinking about your use case, when you are copying from external sources. It would be nice if the default tabsize was the obsidian tab size though.
from obsidian-linter.
on the discord, found vault.getConfig("tabSize").
from obsidian-linter.
I have the rule ready, but I am a bit uncertain about the typescript part.
- is this how you would do it in the
rules.ts
?
(text: string) => {
let tabsize = vault.getConfig("tabSize"); // <- this the proper syntax?
(...)
},
- also, concerning the examples, how exactly do I have to write them, with the indention in the code of the
rules.ts
itself? or does thededent
already deal with that?
from obsidian-linter.
You should test the tabSize syntax in obsidian. If you put the repo in your plugins folder, after you run npm run compile
you should be able to activate it in obsidian and test it.
Yep dedent deals with it, its pretty smart about the indentation.
from obsidian-linter.
okay, I have a working solution ready, but there are two problem.
Problem 1: vault.getConfig("tabSize")
does not work, when compiling, I get the following error:
(!) Plugin typescript: @rollup/plugin-typescript TS2304: Cannot find name 'vault'.
src/rules.ts: (654:23)
654 let tabsize = vault.getConfig("tabSize");
~~~~~
I also tried adding import { App } from 'obsidian';
to the imports at the top of the document, but that did not solve it.
Problem 2: So what I did for now, was to simply use tabsize
as an option, as you suggested before. npm run compile
works fine and all tests are passed, however, npm run lint
has โ surprise โ a problems with me having added tabs.
> [email protected] lint
> eslint . --ext .ts --fix
/Users/chrisgrieser/Google Drive/File Hub/obsidian-linter/src/rules.ts
674:13 error Unexpected tab character no-tabs
676:13 error Unexpected tab character no-tabs
โ 2 problems (2 errors, 0 warnings)
674:13
and 674:13
are, of course, exactly the two positions where I have inserted the tabs for the example. Naturally, removing the tabs for the linter causes the test not to pass. ๐
So assume you would have to change some linter configuration before I can commit this rule?
from obsidian-linter.
Well, at least problem #2 I figured out on my own by using inline comments to temporarily disable linting rules. Will be adding a PR shortly.
from obsidian-linter.
Related Issues (20)
- Bug: Issues with No Bare URLs rule HOT 5
- Some linting rules disrupts header fold states HOT 5
- Question: Possible to Save Current Time When Using Template to Create Note HOT 3
- FR: Add option to skip Liquid tags and content wrapped by them HOT 2
- Bug: forbidden character combinations while copy & pasting the text of a website to a note HOT 4
- FR: Add option to save YAML timestamps in UTC
- FR: Keep Title if It Already Exists HOT 6
- FR: Ignore hyphens in "Space between Chinese Japanese or Korean and English or numbers" HOT 11
- Bug: MisspellingToCorrection not check correctly if my default language in OS settings is English HOT 3
- Bug: `Empty Lines Around Code Fences` can cause problems with nested callouts HOT 1
- FR: Don't auto-complete acronyms
- Bug: Created date gets updated to a different timezone HOT 19
- Question: How do I increase the number of new lines to two before a heading? HOT 2
- Bug: YAML Key Sort option removes multi-line content after literal operator `|` HOT 4
- Bug: tildes in URLs cause the URL to be broken HOT 1
- Bug: "Preserve existing aliases section style" should check Linter's array section style setting to avoid >1 lint HOT 6
- Bug: Indentations for math block removed from callouts or block quotes HOT 5
- Bug: auto โcreatedโ and โmodifiedโ date time in custom format. HOT 3
- FR: Lint selected files via the Files tab (similar to "Lint folder")
- Question: File Specific Rule Disabling in YAML Frontmatter - Hiding/Editing/Commenting Out rules HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from obsidian-linter.