Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support shimmed ruby versions #1407

Merged
merged 13 commits into from
Nov 23, 2023
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
with:
bundler-cache: true
ruby-version: ${{ matrix.ruby }}
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 20.x
cache: yarn
- run: yarn install --frozen-lockfile
- run: yarn test
Expand All @@ -41,9 +41,9 @@ jobs:
with:
bundler-cache: true
ruby-version: "3.0"
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 20.x
cache: yarn
- run: yarn install --frozen-lockfile
- run: yarn checkFormat
Expand All @@ -58,9 +58,9 @@ jobs:
with:
bundler-cache: true
ruby-version: "3.2"
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 20.x
cache: yarn
- run: yarn install --frozen-lockfile
- run: gem build -o prettier.gem
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ file](https://prettier.io/docs/en/configuration.html).

```json
{
"plugins": ["@prettier/plugin-ruby"],
"plugins": ["@prettier/plugin-ruby"]
}
```

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"prettier": "^3.0.0"
},
"devDependencies": {
"eslint": "^8.35.0",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"husky": "^8.0.1",
"jest": "^29.5.0",
"prettier": "^3.0.0",
"prettier": "^3.1.0",
"pretty-quick": "^3.1.2"
},
"eslintConfig": {
Expand Down
15 changes: 10 additions & 5 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,23 @@ export async function spawnServer(opts, killOnExit = true) {
const tmpdir = os.tmpdir();
const filepath = path.join(tmpdir, `prettier-ruby-parser-${process.pid}.txt`);

const default_options = {
env: Object.assign({}, process.env, { LANG: getLang() }),
stdio: ["ignore", "ignore", "inherit"],
detached: true
};
const options = opts.filepath
? { cwd: path.dirname(opts.filepath), ...default_options }
: default_options;

const server = spawn(
opts.rubyExecutablePath || "ruby",
[
url.fileURLToPath(new URL("./server.rb", import.meta.url)),
`--plugins=${getPlugins(opts).join(",")}`,
filepath
],
{
env: Object.assign({}, process.env, { LANG: getLang() }),
stdio: ["ignore", "ignore", "inherit"],
detached: true
}
options
);

server.unref();
Expand Down
11 changes: 8 additions & 3 deletions src/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
require "json"
require "socket"

require "prettier_print"
require "syntax_tree"
require "syntax_tree/haml"
require "syntax_tree/rbs"

# Optional dependencies
%W[syntax_tree/rbs syntax_tree/haml prettier_print].each do |dep|
begin
require dep
rescue LoadError
end
end

# First, require all of the plugins that the user specified.
ARGV.shift[/^--plugins=(.*)$/, 1]
Expand Down
16 changes: 8 additions & 8 deletions test/js/ruby/nodes/lambda.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ describe("lambda", () => {
return expect(`command :foo, -> { ${long} }`).toChangeFormat(
ruby(`
command :foo,
-> {
-> do
${long}
}
end
`)
);
});
Expand All @@ -51,9 +51,9 @@ describe("lambda", () => {
return expect(`command.call :foo, -> { ${long} }`).toChangeFormat(
ruby(`
command.call :foo,
-> {
-> do
${long}
}
end
`)
);
});
Expand All @@ -62,9 +62,9 @@ describe("lambda", () => {
return expect(`command :foo, bar: -> { ${long} }`).toChangeFormat(
ruby(`
command :foo,
bar: -> {
bar: -> do
${long}
}
end
`)
);
});
Expand All @@ -79,9 +79,9 @@ describe("lambda", () => {
${long},
a${long},
aa${long}
) {
) do
true
}
end
`)
);
});
Expand Down