rubocop

VSCode + WSL 2 + Ruby环境搭建详解

穿精又带淫゛_ 提交于 2020-08-17 03:03:01
vscode配置ruby开发环境 vscode近年来发展迅速,几乎在3年之间就抢占了原来vim、sublime text的很多份额,犹记得在2015-2016年的时候,ruby 推荐的开发环境 基本上都是vim和sublime text,然而,随着vscode的发展,vscode下ruby的开发体验已经非常不错。现在基本上使用win 10 wsl2 + vscode + windows terminal的体验已经不逊于mac + vim (sublime) + item 2的体验了 总体步骤 使用win10专业版配置ruby开发环境大致分为以下几步: 开启win10 wsl功能 升级wsl2 安装ubuntu 安装ruby(rvm) 安装vscode 安装vscode wsl扩展 安装vscode ruby相关扩展 经过以上7步就可以开始愉悦的ruby开发了,再开始之前,可以先看个效果图。 1. 开启win10 wsl功能 ruby对Linux和Mac比较友好,在windows下很多第三方库要配合mingw或msys2才能安装,不过好在windows 10提供了Linux子系统,在win10 2004版本中wsl也升级到了wsl2,速度更快,功能更完善。 要使用wsl2需要先在控制面板中开启wsl功能: 适用于Linux的Windows子系统 虚拟机平台 2. 升级wsl2

How to require file from `gem` which are not under `lib` directory?

﹥>﹥吖頭↗ 提交于 2020-05-28 20:05:21
问题 I want to write spec for my rubocop custom cop. This gem has handy helpers defined here. I want to require it. How to achieve what? I've tried to use Gem.find_files , and this gives me ability to require any file in that gem, but only under lib directory. For example: # this requires ...gems/rubocop-0.29.1/lib/rubocop/formatter/formatter_set.rb require Gem.find_files('rubocop/formatter/formatter_set.rb').first # but I need ...gems/rubocop-0.29.1/spec/support/cop_helper.rb The following

burpsuite+jruby+vscode 的开发方式,更简单的burp插件编写

余生长醉 提交于 2020-02-27 21:15:25
为什么要用ruby?ruby语法编码比jython相对简单,编码格式相对舒服,例如标题可以使用中文: jruby安装就是一路next就不讲了,安装好jruby后别忘了设置环境变量 JRUBY_HOME 指向到jruby根目录否则不能使用require语句,如下图: 接下来参照 https://gems.ruby-china.com 重新定位 gem 和 bundle的镜像 之后在vscode中安装插件并配置如下 1: ruby Solargraph (语法服务器)在设置中需要手工开启如下两个地方,可以直接搜索Solargraph: 2: 安装endwise 插件 (end自动补齐) 3: gem install rubocop 4: 重启vscode 参照之前的套路使用一个插件文件和一个热更新的代码,每次hello.rb都会启动run.rb并执行 hello.rb代码如下: #encoding: utf-8 # frozen_string_literal: true # author: k4n5ha0 # 第二行开启了冻结字符串请注意使用方式 require 'java' require 'pathname' java_import 'burp.IBurpExtender' java_import 'burp.IHttpListener' java_import 'burp

If a Rubocop rule is disabled in-line does it need to be re-enabled

北战南征 提交于 2020-02-24 04:54:15
问题 If you disable a Rubocop rule in-line and do not re-enable it, will the rule be disabled for all subsequence files or is an in-line disable limited to the scope of the current file? For example, if I enter this before a couple of methods that I know break the line length rule: # rubocop:disable Metrics/LineLength Is this rule disable for the rest of the file, or for all subsequent files in the current scan? 回答1: In-line config is applied to the given file only (just tested it). 回答2: You can

RSpec & Rubocop / Ruby Style Guide

烈酒焚心 提交于 2019-12-24 16:19:54
问题 when telling the rails scaffold controller to generate rspec tests the generated files don't follow the Ruby Style Guide and thus rubocop throws errors on these. Only a couple of "cops" fail. Style/HashSyntax, Style/StringLiterals, Style/MethodCallParentheses, Style/SpaceInsideHashLiteralBraces, Style/Blocks. I do understand that some of these cops are just style preferences like for example Style/StringLiterals (Prefer single-quoted strings when you don't need string interpolation or special

Ruby rubocop: how to freeze an array constant generated with splat

末鹿安然 提交于 2019-12-23 12:55:41
问题 I'm assigning an array constant like this: NUMS = *(2..9) Rubocop says C: Freeze mutable objects assigned to constants. NUMS = *(2..9) ^^^^^ So I try NUMS = *(2..9).freeze Rubocop says C: Freeze mutable objects assigned to constants. NUMS = *(2..9).freeze ^^^^^^^^^^^^ Tried NUMS = (*(2..9)).freeze Rubocop says E: unexpected token tRPAREN (Using Ruby 2.0 parser; configure using TargetRubyVersion parameter, under AllCops) NUMS = (*(2..9)).freeze ^ Tried NUMS = [1, 2, 3, 4, 5, 6, 7, 8, 9].freeze

Rubocop error 'Class definition is too long ruby'

回眸只為那壹抹淺笑 提交于 2019-12-18 14:55:20
问题 I am getting rubocop error 'Class definition is too long. [236/100]'. My class looks like below: class SomeClassName include HelperModule attr_accessor :aaa, :bbb, :ccc .... methods ..... end What might go wrong? The rubocop docs ClassLength says "length of a class exceeds some maximum value". What does it mean? 回答1: This likely means that your class definition takes more than 100 lines of code. 回答2: Yes, this is because the overall lines are considered to be too many by rubucop. I agree

Rubocop Linelength: How to ignore lines with comments?

我是研究僧i 提交于 2019-12-18 10:11:27
问题 Using a Rails 4 app I would like Rubocop to ignore lines with comments (just a comment or some code with an end of line comment) when checking if a line is to long. Is there a way to do this? 回答1: There is a way to ignore cops on a per line basis. There is also a way to do it via configuration file. Run rubocop --auto-gen-config and it will generate a file that you can use to disable the offenses. The command also gives a hint on what to do to load those options. On a line per line basis, you

How do I suppress Rubocop Conventions?

痞子三分冷 提交于 2019-12-11 07:34:56
问题 Am looking at rubocop but want to start with warnings and errors - we'll get to convention-related alerts later. My question is: how do I invoke rubocop where it will ignore convention-related alerts and only report on Warning, error & fatal messages. Thanks Michael. 回答1: rubocop --only Syntax,Lint From https://github.com/bbatsov/rubocop/issues/2337#issuecomment-150477553 If you don't have any custom severity levels in your configuration, it's quite simple. The Synax cop reports on fatal and

With Rails using Minitest, how can I set up RuboCop to run automatically each time tests are run with rake?

谁都会走 提交于 2019-12-10 15:14:36
问题 When I run the following command, I want RuboCop to inspect application directories I specify before tests run: bundle exec rake test 回答1: I added the following task to lib/tasks/test.rake : require 'rubocop/rake_task' # Add additional test suite definitions to the default test task here namespace :test do desc 'Runs RuboCop on specified directories' RuboCop::RakeTask.new(:rubocop) do |task| # Dirs: app, lib, test task.patterns = ['app/**/*.rb', 'lib/**/*.rb', 'test/**/*.rb'] # Make it easier