Giter Site home page Giter Site logo

sleekbyte / tailor Goto Github PK

View Code? Open in Web Editor NEW
1.4K 35.0 51.0 2.73 MB

Cross-platform static analyzer and linter for Swift.

Home Page: https://sleekbyte.github.io/tailor

License: MIT License

Shell 0.61% ANTLR 6.09% Swift 20.55% Java 69.78% Ruby 0.19% PowerShell 0.55% HTML 2.23%
swift linter static-analyzer apple

tailor's People

Contributors

a4sriniv avatar adityatrivedi avatar alykhank avatar kenji21 avatar nehasingh2293 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tailor's Issues

Restrict redundant parentheses

Do not use parentheses around:

  • control flow constructs
    • for
    • while
    • repeat while
    • if
    • switch
    • guard
  • exception handling constructs
    • throw
    • catch
  • collections
    • array items
    • dictionary items
  • initializer

Enforce lowerCamelCase naming convention

The following constructs should be named using the lowerCamelCase format:

  • method and selector names
func someMethod() {
    // method definition goes here
}
  • variable names
var someVariable = someValue

Restrict number of lines per file and method

Allow user to set a maximum line count restriction in

  • file
  • class/closure/function/struct

By default, the user will be allowed to create files and methods with infinite number of lines.

Enforce absence of spaces

No spaces:

  • between parentheses and content
  • between angle brackets and content
  • between function name and parameter list
  • [ ] around unary operands

Detect lexer/parser errors and abort rule analysis

The ANTLR API does not seem to throw any exceptions but rather just print to STDERR, this output could be captured and tested for emptiness to detect errors and abort walking the partial tree or invoking the FileListener.

Alternatively, investigate use of ANTLRErrorStrategy along with Parser.notifyErrorListeners(java.lang.String) and/or reportError(Parser recognizer, RecognitionException e) to report any kind of RecognitionException.

Enforce TODO comment syntax

Ensure TODO comments are defined as follows in single line comments //:

  • Without developer name
// TODO: <insert mandatory todo comment>
  • With developer name
// TODO(dev-name): <insert mandatory todo comment>

Note: Nested single line comments will be analyzed and flagged.

Allow enabling/disabling each rule individually via flags

This will also help in isolating functional tests to specific features, tests should be modified to use these flags once implemented.

For example (based on Pylint):
--enable=semicolon,uppercamelcase,lowercamelcase,kprefix (whitelist)
AND
--disable=semicolon,redundantparens,closureparens (blacklist)

Enforce UpperCamelCase naming convention

The following constructs should be named using the UpperCamelCase format:

  • class names
class SomeClass {
    // class definition goes here
}
  • enumeration types
enum SomeEnumeration {
    // enumeration definition goes here
}
  • enumeration values
enum CompassPoint {
    case North
    case South
    case East
    case West
}
  • struct names
struct SomeStructure {
    // structure definition goes here
}
  • protocol names
protocol SomeProtocol {
    // protocol definition goes here
}

Port Python code to Java

  • Organize directory structure/packages
  • Port script
    • Use Java runtime for ANTLR
    • Add dependencies to bootstrap/build script
    • Set up pre-commit hooks
  • Port main
  • Relocate ANTLR output
  • Port listeners and utils
    • UpperCamelCase rule
    • Semicolon rule
    • Constant naming convention rule
    • Construct length rule (vertical, i.e. num lines)
    • Line/identifier length rule (horizontal, i.e. num characters)
  • Port output
  • Port unit and functional tests
  • Javadocs, resolve #26

Create project wiki

The project wiki should:

  • specify development environment constraint
  • provide link to contribution guidelines
  • provide link to implemented features
  • list and link to external tools/frameworks along with their licenses that are being used in the project

Enforce indentation style

One of:

  • 4 spaces, no tabs
  • tabs, not spaces
  • 2 spaces (reasoning: to conserve space and prevent line wrapping)

Support multiple source files as input

Multiple positional command line arguments should be supported, each of which is a Swift source file to be analyzed. This includes shell glob expansion.

Enforce maximum item/construct limits

  • Number of functions per class/file
  • Number of constants per file
  • Number of local variables in a class/function
  • Number of parameters that a method/function takes

Upgrade grammar to Swift 2.0

Swift 2.0

New language features to support:

  • replace guard-clause with where-clause
  • update conditions for while, if and guard statements
  • repeat-while loops
  • guard statements
  • availability conditions
  • throw statements
  • try operator
  • do-catch statements
  • defer statements

Omit parentheses if function takes a single closure argument

Preferred:

someFunctionThatTakesAClosure {
    // trailing closure's body goes here
}

Not Preferred:

someFunctionThatTakesAClosure() {
    // trailing closure's body goes here
}

Example:

let digitNames = [
    0: "Zero", 1: "One", 2: "Two",   3: "Three", 4: "Four",
    5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine"
]
let numbers = [16, 58, 510]

let strings = numbers.map {
    (var number) -> String in
    var output = ""
    while number > 0 {
        output = digitNames[number % 10]! + output
        number /= 10
    }
    return output
}
// strings is inferred to be of type [String]
// its value is ["OneSix", "FiveEight", "FiveOneZero"]

Column number specified by printer off by one

The printer counts column numbers from 0 instead of 1. This leads to inaccurate error/warning messages.

Example
If the error message is on line 1 and column 4, then the printer will claim that the error is on line 1 and column 3.

Create functional test harness

The functional test harness will diff the generated output from STDOUT against the expected functional test output *Tests.out.

Enforce naming convention for global and local constants

Users should be given a choice to use lowerCamelCase or UpperCamelCase to name global constants.

  • global
    • lowerCamelCase
    • UpperCamelCase

Users are suggested to use lowerCamelCase names for local constants.

  • local
    • lowerCamelCase

Enforce bracket styles (Part 1)

Related issues: #96, #100, #132, #135

Open brace should be on same line as statement

  • class
class SomeClass: SomeSuperClass {
}

class Demo {
}
  • function
func someMethod() {
}
  • conditional
if someCondition {
}

else if someCondition {
}

else {
}

switch someCase {
  default:
      break
}
  • loops
for var x = 0; x < 10; x+=1 {
}

for ; ; {
}

for var x ; ; {
}

for ; x ; {
}

for ; ; x {
}

for var x; x ; {
}

for var x; ; x {
}

for ; x ; x {
}

while someCondition {
}

repeat {
} while someCondition

for someElement in someCollection {
}
  • initializer
init(length:Double, breadth:Double) {
   self.length = length
   self.breadth = breadth
}
  • struct
struct DemoStruct : SomeParentStruct {
}

struct DemoStruct {
}

Enforce whitespace checks

  • one blank line between methods
  • whitespace around operators when defining them

Preferred

prefix operator += {}

Not Preferred

prefix operator   +-+ {}
prefix operator **    {}
  • only one space between opening construct and { brace (except for compound assignment operators +=)

Preferred

func helloWorld {
 // do something
}

Not Preferred

func helloWorld{
    // do something
}

class hello     {
    var message: String
}
  • one space after // in comments

Preferred

// this is a comment

Not Preferred

//this is a comment
  • start and end multi-line comments with a single space

Preferred

/* This is a
multiline comment */

Not Preferred

/*This is a
multiline comment*/
  • Colon directly after identifier, then space and type name

Preferred

var x: Int = 2

Not Preferred

var x : Int
var y:   String
  • Colon directly after key type, then space and value for dictionary types

Preferred

var x = [ 'key1': 1, 'key2': 2 ]
var y: [ Int: String ]

Not Preferred

var x = [ 'key1' : 1, 'key2':  3]
var y: [ Int :    String ]
  • Colon directly after case label, then space and statements

Preferred

switch character {
case "a": doSomething(a);
default: alert();
}

Not Preferred

switch character {
case "a" : doSomething(a);
default:     alert();
}
  • Colon directly after class/struct/protocol/extension name, followed by space, followed by type inheritance list

Preferred

class ClassName: BaseClass {
}

struct StructName: BaseStruct {
}

protocol ProtocolName: AnotherProtocol {
}

extension TypeName: ProtocolName {
}

Not Preferred

class ClassName : BaseClass {
}

struct StructName:  BaseStruct {
}

protocol ProtocolName:AnotherProtocol {
}

extension TypeName : ProtocolName {
}
  • Single space before and after colon in a conditional expression

Preferred

var x = condition ? a : b

Not Preferred

var x = condition ? a: b
var x = condition ? a   : b
  • Tuple name, followed by colon, followed by a space, followed by value

Preferred

var y = (key: 1, value: 2)

Not Preferred

var y = (key:1, value : 2)
  • Colon directly after typeName, followed by a space in generic parameter clauses

Preferred

func someFunction<T: SomeClass, U: SomeProtocol>(someT: T, someU: U) {
}

Not Preferred

func someFunction<T : SomeClass, U:SomeProtocol>(someT: T, someU: U) {
}
  • Check for a space before and after '->' in function and closure declarations
  • Check for a space before and after '->' in subscripts
  • Check for a space before and after '->' in function types

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.