Giter Club home page Giter Club logo

Comments (9)

platers avatar platers commented on May 26, 2024

Would this logic work?

For every line, count the number of leading spaces, spaces. Replace them with spaces/tabsize tabs.

from obsidian-linter.

chrisgrieser avatar chrisgrieser commented on May 26, 2024

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.

chrisgrieser avatar chrisgrieser commented on May 26, 2024

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.

platers avatar platers commented on May 26, 2024

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.

platers avatar platers commented on May 26, 2024

on the discord, found vault.getConfig("tabSize").

from obsidian-linter.

chrisgrieser avatar chrisgrieser commented on May 26, 2024

I have the rule ready, but I am a bit uncertain about the typescript part.

  1. is this how you would do it in the rules.ts?
(text: string) => {
        let tabsize = vault.getConfig("tabSize"); // <- this the proper syntax?
        (...)
},
  1. 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 the dedent already deal with that?

from obsidian-linter.

platers avatar platers commented on May 26, 2024

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.

chrisgrieser avatar chrisgrieser commented on May 26, 2024

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.

chrisgrieser avatar chrisgrieser commented on May 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.