Skip to content

Commit

Permalink
Lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
benwaffle committed Oct 3, 2019
1 parent 1e4f98e commit 2503646
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 48 deletions.
27 changes: 27 additions & 0 deletions .vala-lint.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Checks]
block-opening-brace-space-before=error
double-semicolon=error
double-spaces=error
ellipsis=off
line-length=warn
naming-convention=off
no-space=error
note=warn
space-before-paren=error
use-of-tabs=error
trailing-newlines=error
trailing-whitespace=error
unnecessary-string-template=error

[Disabler]
disable-by-inline-comments=true

[line-length]
max-line-length=120
ignore-comments=true

[naming-convention]
exceptions=UUID,

[note]
keywords=TODO,FIXME,
8 changes: 4 additions & 4 deletions context.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Vls.Context {
dirty = false;

string version = Config.libvala_version;
string[] parts = version.split(".");
string[] parts = version.split (".");
assert (parts.length == 3);
assert (parts[0] == "0");
// var minor = int.parse (parts[1]);
Expand Down Expand Up @@ -85,10 +85,10 @@ class Vls.Context {
}
}

public Context() {
public Context () {
_defines = new HashSet<string> ();
_packages = new HashSet<string> ();
_usings = new HashSet<string> ();
_usings = new HashSet<string> ();
_sources = new HashMap<string, TextDocument> ();
_csources = new HashSet<string> ();
_vapidirs = new HashSet<string> ();
Expand Down Expand Up @@ -196,7 +196,7 @@ class Vls.Context {
/**
* call this before each semantic update
*/
public void invalidate() {
public void invalidate () {
dirty = true;
}

Expand Down
3 changes: 3 additions & 0 deletions lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

io.elementary.vala-lint -c .vala-lint.conf -d .
4 changes: 2 additions & 2 deletions list_symbols.vala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Vls.ListSymbols : Vala.CodeVisitor {
}
}
}

if (dsym.kind == Method || dsym.kind == Function) {
if (/_lambda\d+_/.match (dsym.name))
return null;
Expand Down Expand Up @@ -425,4 +425,4 @@ class Vls.ListSymbols : Vala.CodeVisitor {
if (expr.source_reference != null && expr.source_reference.file != file) return;
expr.accept_children (this);
}
}
}
64 changes: 32 additions & 32 deletions main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Vls.Server {
this.cc = new HashTable<string, string> (str_hash, str_equal);

Timeout.add (10000, () => {
debug (@"listening...");
debug ("listening...");
return true;
});

Expand All @@ -94,9 +94,9 @@ class Vls.Server {

// hack to prevent other things from corrupting JSON-RPC pipe:
// create a new handle to stdout, and close the old one (or move it to stderr)
var new_stdout_fd = Posix.dup(Posix.STDOUT_FILENO);
Posix.close(Posix.STDOUT_FILENO);
Posix.dup2(Posix.STDERR_FILENO, Posix.STDOUT_FILENO);
var new_stdout_fd = Posix.dup (Posix.STDOUT_FILENO);
Posix.close (Posix.STDOUT_FILENO);
Posix.dup2 (Posix.STDERR_FILENO, Posix.STDOUT_FILENO);

var stdin = new UnixInputStream (Posix.STDIN_FILENO, false);
var stdout = new UnixOutputStream (new_stdout_fd, false);
Expand Down Expand Up @@ -169,7 +169,7 @@ class Vls.Server {

void showMessage (Jsonrpc.Client client, string message, MessageType type) {
try {
client.send_notification ("window/showMessage", buildDict(
client.send_notification ("window/showMessage", buildDict (
type: new Variant.int16 (type),
message: new Variant.string (message)
));
Expand Down Expand Up @@ -229,7 +229,7 @@ class Vls.Server {
}

// for every target, get all target_files
targets_parser.get_root ().get_array().foreach_element ((_1, _2, node) => {
targets_parser.get_root ().get_array ().foreach_element ((_1, _2, node) => {
var target_obj = node.get_object ();
Json.Node target_sources_array = target_obj.get_member ("target_sources");
if (target_sources_array == null)
Expand All @@ -239,13 +239,13 @@ class Vls.Server {
if (target_source.language != "vala") return;

// get all packages
for (int i=0; i<target_source.parameters.length; i++) {
for (int i = 0; i < target_source.parameters.length; i++) {
string param = target_source.parameters[i];
if (param.index_of ("--pkg") == 0) {
if (param == "--pkg") {
if (i+1 < target_source.parameters.length) {
if (i + 1 < target_source.parameters.length) {
// the next argument is the package name
ctx.add_package (target_source.parameters[i+1]);
ctx.add_package (target_source.parameters[i + 1]);
i++;
}
} else {
Expand All @@ -257,8 +257,8 @@ class Vls.Server {
}
} else if (param.index_of ("--vapidir") == 0) {
if (param == "--vapidir") {
if (i+1 < target_source.parameters.length) {
ctx.add_vapidir (target_source.parameters[i+1]);
if (i + 1 < target_source.parameters.length) {
ctx.add_vapidir (target_source.parameters[i + 1]);
i++;
}
} else {
Expand Down Expand Up @@ -458,7 +458,7 @@ class Vls.Server {
}

try {
client.reply (id, buildDict(
client.reply (id, buildDict (
capabilities: buildDict (
textDocumentSync: new Variant.int16 (TextDocumentSyncKind.Full),
definitionProvider: new Variant.boolean (true),
Expand All @@ -481,7 +481,7 @@ class Vls.Server {
}

string name;
var dirs_to_search = new GLib.List<string>();
var dirs_to_search = new GLib.List<string> ();
while ((name = dir.read_name ()) != null) {
string path = Path.build_filename (dirname, name);
if (name == target)
Expand All @@ -492,7 +492,7 @@ class Vls.Server {
}

foreach (string path in dirs_to_search) {
string r = findFile(path, target);
string r = findFile (path, target);
if (r != null)
return r;
}
Expand All @@ -509,8 +509,8 @@ class Vls.Server {
}

T? parse_variant<T> (Variant variant) {
var json = Json.gvariant_serialize(variant);
return Json.gobject_deserialize(typeof(T), json);
var json = Json.gvariant_serialize (variant);
return Json.gobject_deserialize (typeof (T), json);
}

Variant object_to_variant (Object object) throws Error {
Expand All @@ -528,7 +528,7 @@ class Vls.Server {
linepos = pos;
}

return linepos+1 + charno;
return linepos + 1 + charno;
}

void textDocumentDidOpen (Jsonrpc.Client client, Variant @params) {
Expand Down Expand Up @@ -656,7 +656,7 @@ class Vls.Server {
TextDocument? doc = doc_uri == null ? null : ctx.get_source_file (doc_uri);

if (doc != null) {
docs = new ArrayList<TextDocument>();
docs = new ArrayList<TextDocument> ();
docs.add (doc);
} else {
docs = ctx.get_source_files ();
Expand Down Expand Up @@ -690,7 +690,7 @@ class Vls.Server {
var node = Json.gobject_serialize (diag);
array.add_element (node);
} else
array.add_element (Json.gobject_serialize (new Diagnostic() {
array.add_element (Json.gobject_serialize (new Diagnostic () {
severity = DiagnosticSeverity.Error,
message = err.message
}));
Expand Down Expand Up @@ -719,7 +719,7 @@ class Vls.Server {
var node = Json.gobject_serialize (diag);
array.add_element (node);
} else
array.add_element (Json.gobject_serialize (new Diagnostic() {
array.add_element (Json.gobject_serialize (new Diagnostic () {
severity = DiagnosticSeverity.Warning,
message = err.message
}));
Expand All @@ -734,7 +734,7 @@ class Vls.Server {
}

try {
client.send_notification ("textDocument/publishDiagnostics", buildDict(
client.send_notification ("textDocument/publishDiagnostics", buildDict (
uri: new Variant.string (uri),
diagnostics: result
));
Expand All @@ -757,7 +757,7 @@ class Vls.Server {
try {
client.reply (id, new Variant.maybe (VariantType.VARIANT, null));
} catch (Error e) {
debug("[textDocument/definition] failed to reply to client: %s", e.message);
debug ("[textDocument/definition] failed to reply to client: %s", e.message);
}
return;
}
Expand All @@ -768,7 +768,7 @@ class Vls.Server {
try {
client.reply (id, new Variant.maybe (VariantType.VARIANT, null));
} catch (Error e) {
debug("[textDocument/definition] failed to reply to client: %s", e.message);
debug ("[textDocument/definition] failed to reply to client: %s", e.message);
}
return;
}
Expand All @@ -787,10 +787,10 @@ class Vls.Server {
{
assert (best != null);
var sr = best.source_reference;
var from = (long)Server.get_string_pos (file.content, sr.begin.line-1, sr.begin.column-1);
var to = (long)Server.get_string_pos (file.content, sr.end.line-1, sr.end.column);
var from = (long)Server.get_string_pos (file.content, sr.begin.line - 1, sr.begin.column - 1);
var to = (long)Server.get_string_pos (file.content, sr.end.line - 1, sr.end.column);
string contents = file.content [from:to];
debug ("Got node: %s @ %s = %s", best.type_name, sr.to_string(), contents);
debug ("Got node: %s @ %s = %s", best.type_name, sr.to_string (), contents);
}

if (best is Vala.Expression && !(best is Vala.Literal)) {
Expand All @@ -804,7 +804,7 @@ class Vls.Server {
try {
client.reply (id, new Variant.maybe (VariantType.VARIANT, null));
} catch (Error e) {
debug("[textDocument/definition] failed to reply to client: %s", e.message);
debug ("[textDocument/definition] failed to reply to client: %s", e.message);
}
return;
}
Expand Down Expand Up @@ -840,7 +840,7 @@ class Vls.Server {
}
}));
} catch (Error e) {
debug("[textDocument/definition] failed to reply to client: %s", e.message);
debug ("[textDocument/definition] failed to reply to client: %s", e.message);
}
}

Expand All @@ -856,7 +856,7 @@ class Vls.Server {
try {
client.reply (id, new Variant.maybe (VariantType.VARIANT, null));
} catch (Error e) {
debug("[textDocument/documentSymbol] failed to reply to client: %s", e.message);
debug ("[textDocument/documentSymbol] failed to reply to client: %s", e.message);
}
return;
}
Expand All @@ -865,12 +865,12 @@ class Vls.Server {
var syms = new ListSymbols (sourcefile.file);
if (init_params.capabilities.textDocument.documentSymbol.hierarchicalDocumentSymbolSupport)
foreach (var dsym in syms) {
debug(@"found $(dsym.name)");
debug (@"found $(dsym.name)");
array.add_element (Json.gobject_serialize (dsym));
}
else {
foreach (var dsym in syms.flattened ()) {
debug(@"found $(dsym.name)");
debug (@"found $(dsym.name)");
array.add_element (Json.gobject_serialize (new SymbolInformation.from_document_symbol (dsym, p.textDocument.uri)));
}
}
Expand All @@ -886,7 +886,7 @@ class Vls.Server {
void shutdown (Jsonrpc.Server self, Jsonrpc.Client client, string method, Variant id, Variant @params) {
ctx.clear ();
try {
client.reply (id, buildDict(null));
client.reply (id, buildDict (null));
} catch (Error e) {
debug (@"shutdown: failed to reply to client: $(e.message)");
}
Expand Down
20 changes: 10 additions & 10 deletions protocol.vala
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ namespace LanguageServer {
*/
public uint character { get; set; default = -1; }

public int compare(Position other) {
public int compare (Position other) {
return line > other.line ? 1 :
(line == other.line ?
(character > other.character ? 1 :
(character == other.character ? 0 : -1)) : -1);
}

public string to_string() { return @"$line:$character"; }
public string to_string () { return @"$line:$character"; }

public Position to_libvala () {
return new Position () {
Expand All @@ -89,18 +89,18 @@ namespace LanguageServer {
*/
public Position end { get; set; }

public string to_string() { return @"$start -> $end"; }
public string to_string () { return @"$start -> $end"; }

public Range.from_sourceref (Vala.SourceReference sref) {
this.start = new Position.from_libvala (sref.begin);
this.end = new Position.from_libvala (sref.end);
}

public uint hash() {
return this.to_string().hash();
public uint hash () {
return this.to_string ().hash ();
}

public bool equal_to(Range other) { return this.to_string() == other.to_string(); }
public bool equal_to (Range other) { return this.to_string () == other.to_string (); }
}

class Diagnostic : Object {
Expand Down Expand Up @@ -137,9 +137,9 @@ namespace LanguageServer {
* the new text is considered to be the full content of the document.
*/
class TextDocumentContentChangeEvent : Object {
public Range? range { get; set; }
public int rangeLength { get; set; }
public string text { get; set; }
public Range? range { get; set; }
public int rangeLength { get; set; }
public string text { get; set; }
}

enum MessageType {
Expand Down Expand Up @@ -200,7 +200,7 @@ namespace LanguageServer {
}

public new Value Json.Serializable.get_property (ParamSpec pspec) {
Value val = Value(pspec.value_type);
Value val = Value (pspec.value_type);
base.get_property (pspec.get_name (), ref val);
return val;
}
Expand Down

0 comments on commit 2503646

Please sign in to comment.