Git Product home page Git Product logo

ruff_fmt's Introduction

Test

Install

npm

npm install @wasm-fmt/ruff_fmt

jsr.io

npx jsr add @fmt/ruff-fmt

Usage

import init, { format } from "@wasm-fmt/ruff_fmt";

await init();

const input = `x = {  'a':37,'b':42,

'c':927}

y = 'hello ''world'
z = 'hello '+'world'
a = 'hello {}'.format('world')
class foo  (     object  ):
  def f    (self   ):
    return       37*-+2
  def g(self, x,y=42):
      return y
def f  (   a ) :
  return      37+-+a[42-x :  y**3]`;

const formatted = format(input);
console.log(formatted);

with custom options:

import init, { format } from "@wasm-fmt/ruff_fmt";

// ...
const formatted = format(input, {
    indent_style: "space",
    indent_width: 4,
    line_width: 88,
    quote_style: "double",
    magic_trailing_comma: "respect",
});
console.log(formatted);

For Vite users:

import init, { format } from "@wasm-fmt/ruff_fmt/vite";

// ...

dprint plugin

dprint config add wasm-fmt/ruff_fmt

How does it work?

Ruff is an extremely fast Python linter, written in Rust.

This package is a WebAssembly build of Ruff formatter, with a JavaScript wrapper.

ruff_fmt's People

Contributors

magic-akari avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ruff_fmt's Issues

Support for dynamic importing?

I am using vite in react.js and in my async function I am trying to dynamically import the package.

async function formatCode(code) {
    const init = await import("@wasm-fmt/ruff_fmt/vite");
    const { format } = await import("@wasm-fmt/ruff_fmt/vite");
    await init();
    return await format(code);
}

I am getting this error response:

error
init is not a function

Does this package support this kind of dynamic importing?

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.