代码在github页面上格式不正确

时间:2018-08-21 03:50:02

标签: github

例如,我有以下代码

https://github.com/kenpeter/mb/blob/master/lib/Processor.js

我在vim中使用了2个空格,并且在vim中运行良好。当代码在github上时,它不是格式化的。有人知道如何解决吗?代码在github页面上看起来像这样。

'use strict';

const Employee = require('./Employee');
const Util = require('./Util');

let util = new Util();
let Processor = function() {};

Processor.prototype.process = async function(taxObj, csvArr, fileName='../data/output.csv') {
    DEBUG && console.log('process');

    let item;
    let currTaxObj;
    let rightTaxSlot;
    let edge;
    let base;
    let taxRate;
    let buf = [];
    let employee;

    csvArr.map((item) => {
        employee = new Employee();

        // fill employee model
    employee.firstName = item.firstName;
    employee.lastName = item.lastName;
    employee.annualSalary = item.annualSalary;
    employee.superRate = util.percentToNum(item.superRate);
    employee.timePeriod = item.timePeriod;
    employee.startPeriod = util.parseTimePeriod(item.timePeriod)[0] + ' ' + TIME_PERIOD_YEAR;
    employee.endPeriod = util.parseTimePeriod(item.timePeriod)[1] + ' ' + TIME_PERIOD_YEAR;

        // get right tax slot
    currTaxObj = util.getTaxData(taxObj, employee.startPeriod, employee.endPeriod);
    rightTaxSlot = util.getRightTaxSlot(currTaxObj, employee.annualSalary);

    employee.grossIncome = util.buildGrossIncome(employee.annualSalary);
    employee.fullName = employee.buildFullName();

    // build income tax
    base = rightTaxSlot['base'];
    edge = rightTaxSlot['edge'];
    taxRate = rightTaxSlot['rate'];

    employee.incomeTax = util.buildIncomeTax(employee.annualSalary, base, edge, taxRate);
    employee.netIncome = util.buildNetIncome(employee.grossIncome, employee.incomeTax);
    employee.mySuper = util.buildMySuper(employee.grossIncome, employee.superRate);

    buf.push(employee); 
    }); 

    return await util.print(buf, fileName);
}

module.exports = Processor;

1 个答案:

答案 0 :(得分:1)

在您的GitHub页面上没有看到任何格式问题。
注释已正确对齐。

我检查了adding ?ts=4 to the URL中是否有任何制表符而不是空格,但没有任何变化(意味着仅使用空格)

检查您的vim settings, as described here
尤其是set tabstop=4set expandtab