.FSHFQMVHJO DPO fi HVSBUJPOPOUIF 3VCP$PQTJEF QMVHJO SVCPDPQSBJMT SVCPDPQZNM QMVHJO SVCPDPQSTQFD SVOOFS 3VCP$PQ $PO fi H-PBEFS encapsulate 2. read plugin info and pass the context 2. read plugin info and pass the context 1.read user config 3. merge 3. merge
< LintRoller::Plugin def about def supported?(context) def rules(_context) end end end *OIFSJUGSPN-JOU3PMMFS1MVHJO Define a plugin class RuboCop::Example::Plugin
def rules(_context) LintRoller::Rules.new( type: :path, config_format: :rubocop, value: "#{__dir__}/../../../config/default.yml" ) end end NOTE: There are no dependencies on RuboCop's API like those seen in the "Inject" hack %F fi OFSVMFTNFUIPEUIBUSFUVSOTB -JOU3PMMFS3VMFTXJUIUIFJOGP3VCP$PQ OFFETUPMPDBUFUIFQMVHJODPO fi H 3BJTFTBOFYDFQUJPOJGOPUEF fi OFE
plugins) plugins = Plugin::Loader.load(plugins) ConfigurationIntegrator. integrate_plugins_into_rubocop_config( rubocop_config, plugins ) plugins end end end *OUFSOBM"1*XIFSF3VCP$PQMPBETQMVHJOT BOENFSHFTDPO fi HT
do |name, config| next unless plugin_config['enabled'] plugin_class = constantize_plugin_from(name, config) plugin_class.new(plugin_config) end end name = Gem.loaded_specs[plugin_name].metadata[ 'default_lint_roller_plugin' ] Kernel.const_get(name) Implementation Details 3VCP$PQ1MVHJO-PBEFS (FUTUIFQMVHJODPOTUGSPN QMVHJOTHFNTQFDNFUBEBUB
plugins.reject { |plugin| plugin.supported?(runner_context) } return if unsupported_plugins.none? raise NotSupportedError, unsupported_plugins end end class Plugin < LintRoller::Plugin def supported?(context) context.engine == :rubocop end Plugin's Implementation
= RuboCop::LSP::Runtime.new(config) end def run_diagnostic(uri, document) @runtime.offenses(uri_to_path(uri), document.source, document.encoding) end def run_formatting(uri, document) @runtime.format(uri_to_path(uri), document.source, command: '...') end $SFBUFTUIF3VOUJNFDMBTTUPIBOEMFDBMMCBDLTGSPN3VCZ-41 %F fi OFTEFMFHBUJPOGSPNUIFSVO@EJBHOPTUJDDBMMCBDL %F fi OFTEFMFHBUJPOGSPNUIFSVO@GPSNBUUJOHDBMMCBDL
def initialized(prism_result) @prism_result = prism_result end def parse_lex(_source, **_prism_options) @prism_result end end end 💡An internal class for duck typing with parse_lex. 4UPSFUIFQBSTFESFTVMUGSPN1SJTN 3FUVSOUIFQBSTFESFTVMUGSPN1SJTNXJUIPVUQBSTJOH
) # The parser_class is chosen by version and engine. parser_class = Prism::Translation::Parser34 ... prism_parsed = PrismParsed.new(prism_result) parser_instance = parser_class.new( builder, parser: prism_parsed ) ... end $SFBUFBDVTUPNQBSTFS VTJOHB1SJTNSFTVMU 3FQMBDFXJUIBQBSTFSJOUFSGBDFDMBTTUIBU SFVTFTUIFHJWFO1SJTNSFTVMU