prettier 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +368 -0
- data/CODE_OF_CONDUCT.md +76 -0
- data/CONTRIBUTING.md +143 -0
- data/LICENSE +21 -0
- data/README.md +151 -0
- data/bin/console +7 -0
- data/exe/rbprettier +8 -0
- data/lib/prettier.rb +18 -0
- data/lib/prettier/rake/task.rb +57 -0
- data/node_modules/prettier/bin-prettier.js +44620 -0
- data/node_modules/prettier/index.js +42565 -0
- data/node_modules/prettier/third-party.js +5326 -0
- data/package.json +39 -0
- data/src/builders.js +9 -0
- data/src/escapePattern.js +45 -0
- data/src/nodes.js +594 -0
- data/src/nodes/alias.js +32 -0
- data/src/nodes/arrays.js +162 -0
- data/src/nodes/blocks.js +66 -0
- data/src/nodes/calls.js +28 -0
- data/src/nodes/case.js +57 -0
- data/src/nodes/commands.js +70 -0
- data/src/nodes/conditionals.js +154 -0
- data/src/nodes/hashes.js +134 -0
- data/src/nodes/hooks.js +15 -0
- data/src/nodes/lambdas.js +59 -0
- data/src/nodes/loops.js +46 -0
- data/src/nodes/methods.js +42 -0
- data/src/nodes/params.js +75 -0
- data/src/nodes/regexp.js +18 -0
- data/src/nodes/rescue.js +77 -0
- data/src/nodes/strings.js +143 -0
- data/src/parse.js +16 -0
- data/src/print.js +23 -0
- data/src/ripper.rb +542 -0
- data/src/ruby.js +127 -0
- data/src/toProc.js +82 -0
- data/src/utils.js +150 -0
- metadata +109 -0
data/src/ruby.js
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
const parse = require("./parse");
|
2
|
+
const print = require("./print");
|
3
|
+
|
4
|
+
const pragmaPattern = /#\s*@(prettier|format)/;
|
5
|
+
const hasPragma = text => pragmaPattern.test(text);
|
6
|
+
|
7
|
+
/*
|
8
|
+
* metadata mostly pulled from linguist and rubocop:
|
9
|
+
* https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
|
10
|
+
* https://github.com/rubocop-hq/rubocop/blob/master/spec/rubocop/target_finder_spec.rb
|
11
|
+
*/
|
12
|
+
|
13
|
+
module.exports = {
|
14
|
+
languages: [
|
15
|
+
{
|
16
|
+
name: "Ruby",
|
17
|
+
parsers: ["ruby"],
|
18
|
+
extensions: [
|
19
|
+
".arb",
|
20
|
+
".axlsx",
|
21
|
+
".builder",
|
22
|
+
".eye",
|
23
|
+
".fcgi",
|
24
|
+
".gemfile",
|
25
|
+
".gemspec",
|
26
|
+
".god",
|
27
|
+
".jb",
|
28
|
+
".jbuilder",
|
29
|
+
".mspec",
|
30
|
+
".opal",
|
31
|
+
".pluginspec",
|
32
|
+
".podspec",
|
33
|
+
".rabl",
|
34
|
+
".rake",
|
35
|
+
".rb",
|
36
|
+
".rbuild",
|
37
|
+
".rbw",
|
38
|
+
".rbx",
|
39
|
+
".ru",
|
40
|
+
".ruby",
|
41
|
+
".thor",
|
42
|
+
".watchr"
|
43
|
+
],
|
44
|
+
filenames: [
|
45
|
+
".irbrc",
|
46
|
+
".pryrc",
|
47
|
+
"Appraisals",
|
48
|
+
"Berksfile",
|
49
|
+
"Brewfile",
|
50
|
+
"Buildfile",
|
51
|
+
"Capfile",
|
52
|
+
"Cheffile",
|
53
|
+
"Dangerfile",
|
54
|
+
"Deliverfile",
|
55
|
+
"Fastfile",
|
56
|
+
"Gemfile",
|
57
|
+
"Guardfile",
|
58
|
+
"Jarfile",
|
59
|
+
"Mavenfile",
|
60
|
+
"Podfile",
|
61
|
+
"Puppetfile",
|
62
|
+
"Rakefile",
|
63
|
+
"Snapfile",
|
64
|
+
"Thorfile",
|
65
|
+
"Vagabondfile",
|
66
|
+
"Vagrantfile",
|
67
|
+
"buildfile"
|
68
|
+
],
|
69
|
+
interpreters: ["jruby", "macruby", "rake", "rbx", "ruby"],
|
70
|
+
linguistLanguageId: 326,
|
71
|
+
vscodeLanguageIds: ["ruby"]
|
72
|
+
}
|
73
|
+
],
|
74
|
+
parsers: {
|
75
|
+
ruby: {
|
76
|
+
parse,
|
77
|
+
astFormat: "ruby",
|
78
|
+
hasPragma
|
79
|
+
}
|
80
|
+
},
|
81
|
+
printers: {
|
82
|
+
ruby: {
|
83
|
+
print
|
84
|
+
}
|
85
|
+
},
|
86
|
+
options: {
|
87
|
+
addTrailingCommas: {
|
88
|
+
type: "boolean",
|
89
|
+
category: "Global",
|
90
|
+
default: false,
|
91
|
+
description:
|
92
|
+
"Adds a trailing comma to array literals, hash literals, and method calls."
|
93
|
+
},
|
94
|
+
inlineConditionals: {
|
95
|
+
type: "boolean",
|
96
|
+
category: "Global",
|
97
|
+
default: true,
|
98
|
+
description:
|
99
|
+
"When it fits on one line, allows if and unless statements to use the modifier form."
|
100
|
+
},
|
101
|
+
inlineLoops: {
|
102
|
+
type: "boolean",
|
103
|
+
category: "Global",
|
104
|
+
default: true,
|
105
|
+
description:
|
106
|
+
"When it fits on one line, allows while and until statements to use the modifier form."
|
107
|
+
},
|
108
|
+
preferHashLabels: {
|
109
|
+
type: "boolean",
|
110
|
+
category: "Global",
|
111
|
+
default: true,
|
112
|
+
description:
|
113
|
+
"When possible, uses the shortened hash key syntax, as opposed to hash rockets."
|
114
|
+
},
|
115
|
+
preferSingleQuotes: {
|
116
|
+
type: "boolean",
|
117
|
+
category: "Global",
|
118
|
+
default: true,
|
119
|
+
description:
|
120
|
+
"When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals."
|
121
|
+
}
|
122
|
+
},
|
123
|
+
defaultOptions: {
|
124
|
+
printWidth: 80,
|
125
|
+
tabWidth: 2
|
126
|
+
}
|
127
|
+
};
|
data/src/toProc.js
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
const isCall = node => ["::", "."].includes(node) || node.type === "@period";
|
2
|
+
|
3
|
+
// If you have a simple block that only calls a method on the single required
|
4
|
+
// parameter that is passed to it, then you can replace that block with the
|
5
|
+
// simpler `Symbol#to_proc`. Meaning, it would go from:
|
6
|
+
//
|
7
|
+
// [1, 2, 3].map { |i| i.to_s }
|
8
|
+
//
|
9
|
+
// to:
|
10
|
+
//
|
11
|
+
// [1, 2, 3].map(&:to_s)
|
12
|
+
//
|
13
|
+
// This works with `do` blocks as well.
|
14
|
+
const toProc = node => {
|
15
|
+
if (!node) {
|
16
|
+
return null;
|
17
|
+
}
|
18
|
+
|
19
|
+
const [variables, blockContents] = node.body;
|
20
|
+
|
21
|
+
// Ensure that there are variables being passed to this block.
|
22
|
+
const params = variables && variables.body[0];
|
23
|
+
if (!params || params.type !== "params") {
|
24
|
+
return null;
|
25
|
+
}
|
26
|
+
|
27
|
+
// Ensure there is one and only one parameter, and that it is required.
|
28
|
+
const reqParams = params.body[0];
|
29
|
+
const otherParams = params.body.slice(1);
|
30
|
+
if (
|
31
|
+
!Array.isArray(reqParams) ||
|
32
|
+
reqParams.length !== 1 ||
|
33
|
+
otherParams.some(Boolean)
|
34
|
+
) {
|
35
|
+
return null;
|
36
|
+
}
|
37
|
+
|
38
|
+
let statements;
|
39
|
+
if (blockContents.type === "bodystmt") {
|
40
|
+
// We’re in a `do` block
|
41
|
+
const blockStatements = blockContents.body[0];
|
42
|
+
const rescueElseEnsure = blockStatements.body.slice(1);
|
43
|
+
|
44
|
+
// You can’t use the to_proc shortcut if you’re rescuing
|
45
|
+
if (rescueElseEnsure.some(Boolean)) {
|
46
|
+
return null;
|
47
|
+
}
|
48
|
+
|
49
|
+
statements = blockStatements;
|
50
|
+
} else {
|
51
|
+
// We’re in a brace block
|
52
|
+
statements = blockContents;
|
53
|
+
}
|
54
|
+
|
55
|
+
// Ensure the block contains only one statement
|
56
|
+
if (statements.body.length !== 1) {
|
57
|
+
return null;
|
58
|
+
}
|
59
|
+
|
60
|
+
// Ensure that statement is a call
|
61
|
+
const [statement] = statements.body;
|
62
|
+
if (statement.type !== "call") {
|
63
|
+
return null;
|
64
|
+
}
|
65
|
+
|
66
|
+
// Ensure the call is a method of the block argument
|
67
|
+
const [varRef, call, method, args] = statement.body;
|
68
|
+
|
69
|
+
if (
|
70
|
+
varRef.type !== "var_ref" ||
|
71
|
+
varRef.body[0].body !== reqParams[0].body ||
|
72
|
+
!isCall(call) ||
|
73
|
+
method.type !== "@ident" ||
|
74
|
+
args
|
75
|
+
) {
|
76
|
+
return null;
|
77
|
+
}
|
78
|
+
|
79
|
+
return `&:${method.body}`;
|
80
|
+
};
|
81
|
+
|
82
|
+
module.exports = toProc;
|
data/src/utils.js
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
const {
|
2
|
+
breakParent,
|
3
|
+
concat,
|
4
|
+
hardline,
|
5
|
+
lineSuffix,
|
6
|
+
literalline
|
7
|
+
} = require("./builders");
|
8
|
+
|
9
|
+
const concatBody = (path, opts, print) => concat(path.map(print, "body"));
|
10
|
+
|
11
|
+
const docLength = doc => {
|
12
|
+
if (doc.length) {
|
13
|
+
return doc.length;
|
14
|
+
}
|
15
|
+
|
16
|
+
if (doc.parts) {
|
17
|
+
return doc.parts.reduce((sum, child) => sum + docLength(child), 0);
|
18
|
+
}
|
19
|
+
|
20
|
+
if (doc.contents) {
|
21
|
+
return docLength(doc.contents);
|
22
|
+
}
|
23
|
+
|
24
|
+
return 0;
|
25
|
+
};
|
26
|
+
|
27
|
+
const empty = () => "";
|
28
|
+
|
29
|
+
const first = (path, opts, print) => path.call(print, "body", 0);
|
30
|
+
|
31
|
+
const hasAncestor = (path, types) => {
|
32
|
+
let parent = 0;
|
33
|
+
let parentNode = path.getParentNode();
|
34
|
+
|
35
|
+
while (parentNode) {
|
36
|
+
if (types.includes(parentNode.type)) {
|
37
|
+
return true;
|
38
|
+
}
|
39
|
+
|
40
|
+
parent += 1;
|
41
|
+
parentNode = path.getParentNode(parent);
|
42
|
+
}
|
43
|
+
|
44
|
+
return false;
|
45
|
+
};
|
46
|
+
|
47
|
+
const literal = value => () => value;
|
48
|
+
|
49
|
+
const makeArgs = (path, opts, print, argsIndex) => {
|
50
|
+
let argNodes = path.getValue().body[argsIndex];
|
51
|
+
const argPattern = [print, "body", argsIndex, "body"];
|
52
|
+
|
53
|
+
if (argNodes.type === "args_add_block") {
|
54
|
+
[argNodes] = argNodes.body;
|
55
|
+
argPattern.push(0, "body");
|
56
|
+
}
|
57
|
+
|
58
|
+
const args = path.call(print, "body", argsIndex);
|
59
|
+
const heredocs = [];
|
60
|
+
|
61
|
+
argNodes.body.forEach((argNode, index) => {
|
62
|
+
let pattern;
|
63
|
+
let heredoc;
|
64
|
+
|
65
|
+
if (argNode.type === "heredoc") {
|
66
|
+
pattern = [index, "body"];
|
67
|
+
heredoc = argNode;
|
68
|
+
} else if (
|
69
|
+
argNode.type === "string_literal" &&
|
70
|
+
argNode.body[0].type === "heredoc"
|
71
|
+
) {
|
72
|
+
pattern = [index, "body", 0, "body"];
|
73
|
+
[heredoc] = argNode.body;
|
74
|
+
} else {
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
|
78
|
+
const content = path.map.apply(path, argPattern.slice().concat(pattern));
|
79
|
+
heredocs.push(
|
80
|
+
concat([literalline].concat(content).concat([heredoc.ending]))
|
81
|
+
);
|
82
|
+
args[index] = heredoc.beging;
|
83
|
+
});
|
84
|
+
|
85
|
+
return { args, heredocs };
|
86
|
+
};
|
87
|
+
|
88
|
+
const makeCall = (path, opts, print) => {
|
89
|
+
const operation = path.getValue().body[1];
|
90
|
+
|
91
|
+
if ([".", "&."].includes(operation)) {
|
92
|
+
return operation;
|
93
|
+
}
|
94
|
+
|
95
|
+
return operation === "::" ? "." : path.call(print, "body", 1);
|
96
|
+
};
|
97
|
+
|
98
|
+
const makeList = (path, opts, print) => path.map(print, "body");
|
99
|
+
|
100
|
+
const prefix = value => (path, opts, print) =>
|
101
|
+
concat([value, path.call(print, "body", 0)]);
|
102
|
+
|
103
|
+
const printComments = (printed, start, comments) => {
|
104
|
+
let node = printed;
|
105
|
+
|
106
|
+
comments.forEach(comment => {
|
107
|
+
if (comment.start < start) {
|
108
|
+
node = concat([
|
109
|
+
comment.break ? breakParent : "",
|
110
|
+
comment.body,
|
111
|
+
hardline,
|
112
|
+
node
|
113
|
+
]);
|
114
|
+
} else {
|
115
|
+
node = concat([
|
116
|
+
node,
|
117
|
+
comment.break ? breakParent : "",
|
118
|
+
lineSuffix(` ${comment.body}`)
|
119
|
+
]);
|
120
|
+
}
|
121
|
+
});
|
122
|
+
|
123
|
+
return node;
|
124
|
+
};
|
125
|
+
|
126
|
+
const skipAssignIndent = node =>
|
127
|
+
["array", "hash", "heredoc", "lambda", "regexp_literal"].includes(
|
128
|
+
node.type
|
129
|
+
) ||
|
130
|
+
(node.type === "call" && skipAssignIndent(node.body[0])) ||
|
131
|
+
(node.type === "string_literal" && node.body[0].type === "heredoc");
|
132
|
+
|
133
|
+
const surround = (left, right) => (path, opts, print) =>
|
134
|
+
concat([left, path.call(print, "body", 0), right]);
|
135
|
+
|
136
|
+
module.exports = {
|
137
|
+
concatBody,
|
138
|
+
docLength,
|
139
|
+
empty,
|
140
|
+
first,
|
141
|
+
hasAncestor,
|
142
|
+
literal,
|
143
|
+
makeArgs,
|
144
|
+
makeCall,
|
145
|
+
makeList,
|
146
|
+
prefix,
|
147
|
+
printComments,
|
148
|
+
skipAssignIndent,
|
149
|
+
surround
|
150
|
+
};
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prettier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.12.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Deisz
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.3'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
executables:
|
44
|
+
- rbprettier
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- CHANGELOG.md
|
49
|
+
- CODE_OF_CONDUCT.md
|
50
|
+
- CONTRIBUTING.md
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
- bin/console
|
54
|
+
- exe/rbprettier
|
55
|
+
- lib/prettier.rb
|
56
|
+
- lib/prettier/rake/task.rb
|
57
|
+
- node_modules/prettier/bin-prettier.js
|
58
|
+
- node_modules/prettier/index.js
|
59
|
+
- node_modules/prettier/third-party.js
|
60
|
+
- package.json
|
61
|
+
- src/builders.js
|
62
|
+
- src/escapePattern.js
|
63
|
+
- src/nodes.js
|
64
|
+
- src/nodes/alias.js
|
65
|
+
- src/nodes/arrays.js
|
66
|
+
- src/nodes/blocks.js
|
67
|
+
- src/nodes/calls.js
|
68
|
+
- src/nodes/case.js
|
69
|
+
- src/nodes/commands.js
|
70
|
+
- src/nodes/conditionals.js
|
71
|
+
- src/nodes/hashes.js
|
72
|
+
- src/nodes/hooks.js
|
73
|
+
- src/nodes/lambdas.js
|
74
|
+
- src/nodes/loops.js
|
75
|
+
- src/nodes/methods.js
|
76
|
+
- src/nodes/params.js
|
77
|
+
- src/nodes/regexp.js
|
78
|
+
- src/nodes/rescue.js
|
79
|
+
- src/nodes/strings.js
|
80
|
+
- src/parse.js
|
81
|
+
- src/print.js
|
82
|
+
- src/ripper.rb
|
83
|
+
- src/ruby.js
|
84
|
+
- src/toProc.js
|
85
|
+
- src/utils.js
|
86
|
+
homepage: https://github.com/prettier/plugin-ruby#readme
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubygems_version: 3.0.3
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: prettier plugin for the Ruby programming language
|
109
|
+
test_files: []
|